Skip to content

Commit aea832f

Browse files
add link explorer forwarding
1 parent a4f2e84 commit aea832f

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

lib/ontologies_api_client/base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def type
6767
end
6868

6969
def self.explore(id)
70-
path = collection_path
70+
path = self.respond_to?(:collection_path) ? collection_path : ''
7171
id = "#{path}/#{id}" unless id.include?(path)
7272
inst = self.new(values: {id: id})
7373
LinkedData::Client::LinkExplorer.new({}, inst)

lib/ontologies_api_client/link_explorer.rb

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,18 @@ def initialize(links, instance)
1111
@instance = instance
1212
end
1313

14+
15+
def get(params = {})
16+
get_link(@instance.id, params)
17+
end
18+
1419
def method_missing(meth, *args, &block)
1520
if combined_links.key?(meth.to_s)
1621
explore_link(meth, *args)
1722
elsif meth == :batch
1823
explore_link(args)
1924
elsif !@instance.id.blank?
20-
link = "#{@instance.id}/#{meth}"
21-
get_link(link, args.first)
25+
forward_explore(meth, *args)
2226
else
2327
super
2428
end
@@ -56,6 +60,13 @@ def combined_links
5660

5761
private
5862

63+
def forward_explore(meth, *args)
64+
sub_id = Array(args).find { |x| x.is_a?(String) } || ''
65+
link = "#{@instance.id}/#{meth}/#{CGI.escape(sub_id)}".chomp('/')
66+
@instance.id = link
67+
LinkExplorer.new(@links, @instance)
68+
end
69+
5970
def get_link(link, params, replacements = [], full_attributes = {})
6071
url = replace_template_elements(link.to_s, replacements)
6172
if link.respond_to? :media_type

test/models/test_explore.rb

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
require_relative '../test_case'
22
require 'pry'
33

4+
module Models
5+
def self.method_missing
6+
binding.pry
7+
end
8+
end
49
class LinkExploreTest < LinkedData::Client::TestCase
510

611
def test_explore
7-
sub_direct_explore = LinkedData::Client::Models::Ontology.explore('MEDDRA').latest_submission(include: 'all')
12+
sub_direct_explore = LinkedData::Client::Models::Ontology.explore('MEDDRA')
13+
.latest_submission
14+
.get(include: 'all')
15+
816
sub_indirect_explore = LinkedData::Client::Models::Ontology.find('MEDDRA').explore.latest_submission
917
sub_direct_explore.to_hash.each do |key, value|
1018
value_to_compare = sub_indirect_explore[key]
@@ -16,4 +24,22 @@ def test_explore
1624
end
1725
end
1826

27+
def test_explore_class
28+
29+
id = 'http://purl.org/sig/ont/fma/fma62955'
30+
cls = LinkedData::Client::Models::Ontology.explore('FMA')
31+
.classes(id)
32+
.children
33+
.get
34+
35+
assert_not_empty cls.collection
36+
37+
cls = LinkedData::Client::Models::Ontology.explore('FMA')
38+
.classes(id)
39+
.children
40+
.get(include: 'prefLabel')
41+
42+
assert_not_empty cls.collection
43+
end
44+
1945
end

0 commit comments

Comments
 (0)