Skip to content

Commit

Permalink
Deprecate collection's find method in favor of get
Browse files Browse the repository at this point in the history
  • Loading branch information
jvendetti committed Aug 14, 2024
1 parent 4a8fcdc commit e6e30ed
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
8 changes: 3 additions & 5 deletions lib/ontologies_api_client/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,11 @@ def where(params = {}, &block)
end
end

##
# Find a resource by id
#
# @deprecated Use {#get} instead
def find(id, params = {})
found = where do |obj|
obj.id.eql?(id)
end
found.first
get(id, params)
end

##
Expand Down
6 changes: 5 additions & 1 deletion lib/ontologies_api_client/models/ontology.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,15 @@ def self.find_by(attrs, *args)
# Override to search for views as well by default
# Views get hidden on the REST service unless the `include_views`
# parameter is set to `true`
def find(id, params = {})
def self.find(id, params = {})
params[:include_views] = params[:include_views] || true
super(id, params)
end

def self.find_by_acronym(acronym, params = {})
[find(acronym, params)]
end

##
# Include parameters commonly used with ontologies
def self.include_params
Expand Down
31 changes: 31 additions & 0 deletions test/models/test_ontology.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

require_relative '../test_case'

class OntologyTest < LinkedData::Client::TestCase
def test_find_by_acronym
result = LinkedData::Client::Models::Ontology.find_by_acronym('SNOMEDCT')
refute_empty result
assert_instance_of Array, result
assert_equal 1, result.length

ont = result.first
assert_instance_of LinkedData::Client::Models::Ontology, ont
assert_equal 'https://data.bioontology.org/ontologies/SNOMEDCT', ont.id
assert_equal 'SNOMEDCT', ont.acronym
end

def test_find
ont = LinkedData::Client::Models::Ontology.find('SNOMEDCT')
refute_nil ont
assert_instance_of LinkedData::Client::Models::Ontology, ont
assert_equal 'https://data.bioontology.org/ontologies/SNOMEDCT', ont.id
assert_equal 'SNOMEDCT', ont.acronym

ont = LinkedData::Client::Models::Ontology.find('BiositemapIM')
refute_nil ont
assert_instance_of LinkedData::Client::Models::Ontology, ont
assert_equal 'https://data.bioontology.org/ontologies/BiositemapIM', ont.id
assert_equal 'BiositemapIM', ont.acronym
end
end

0 comments on commit e6e30ed

Please sign in to comment.