Skip to content

Commit

Permalink
add link explorer forwarding
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Jan 26, 2025
1 parent a4f2e84 commit aea832f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/ontologies_api_client/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def type
end

def self.explore(id)
path = collection_path
path = self.respond_to?(:collection_path) ? collection_path : ''
id = "#{path}/#{id}" unless id.include?(path)
inst = self.new(values: {id: id})
LinkedData::Client::LinkExplorer.new({}, inst)
Expand Down
15 changes: 13 additions & 2 deletions lib/ontologies_api_client/link_explorer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,18 @@ def initialize(links, instance)
@instance = instance
end


def get(params = {})
get_link(@instance.id, params)
end

def method_missing(meth, *args, &block)
if combined_links.key?(meth.to_s)
explore_link(meth, *args)
elsif meth == :batch
explore_link(args)
elsif !@instance.id.blank?
link = "#{@instance.id}/#{meth}"
get_link(link, args.first)
forward_explore(meth, *args)
else
super
end
Expand Down Expand Up @@ -56,6 +60,13 @@ def combined_links

private

def forward_explore(meth, *args)
sub_id = Array(args).find { |x| x.is_a?(String) } || ''
link = "#{@instance.id}/#{meth}/#{CGI.escape(sub_id)}".chomp('/')
@instance.id = link
LinkExplorer.new(@links, @instance)
end

def get_link(link, params, replacements = [], full_attributes = {})
url = replace_template_elements(link.to_s, replacements)
if link.respond_to? :media_type
Expand Down
28 changes: 27 additions & 1 deletion test/models/test_explore.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
require_relative '../test_case'
require 'pry'

module Models
def self.method_missing
binding.pry
end
end
class LinkExploreTest < LinkedData::Client::TestCase

def test_explore
sub_direct_explore = LinkedData::Client::Models::Ontology.explore('MEDDRA').latest_submission(include: 'all')
sub_direct_explore = LinkedData::Client::Models::Ontology.explore('MEDDRA')
.latest_submission
.get(include: 'all')

sub_indirect_explore = LinkedData::Client::Models::Ontology.find('MEDDRA').explore.latest_submission
sub_direct_explore.to_hash.each do |key, value|
value_to_compare = sub_indirect_explore[key]
Expand All @@ -16,4 +24,22 @@ def test_explore
end
end

def test_explore_class

id = 'http://purl.org/sig/ont/fma/fma62955'
cls = LinkedData::Client::Models::Ontology.explore('FMA')
.classes(id)
.children
.get

assert_not_empty cls.collection

cls = LinkedData::Client::Models::Ontology.explore('FMA')
.classes(id)
.children
.get(include: 'prefLabel')

assert_not_empty cls.collection
end

end

0 comments on commit aea832f

Please sign in to comment.