@@ -11,11 +11,17 @@ def initialize(links, instance)
1111 @instance = instance
1212 end
1313
14+ def get ( params = { } )
15+ get_link ( @instance . id , params )
16+ end
17+
1418 def method_missing ( meth , *args , &block )
1519 if combined_links . key? ( meth . to_s )
1620 explore_link ( meth , *args )
1721 elsif meth == :batch
1822 explore_link ( args )
23+ elsif !@instance . id . blank?
24+ forward_explore ( meth , *args )
1925 else
2026 super
2127 end
@@ -43,10 +49,7 @@ def explore_link(*args)
4349 ids = link . map { |l | l . to_s }
4450 value_cls . where { |o | ids . include? ( o . id ) }
4551 else
46- url = replace_template_elements ( link . to_s , replacements )
47- value_cls = LinkedData ::Client ::Base . class_for_type ( link . media_type )
48- params [ :include ] ||= value_cls . attributes ( full_attributes )
49- HTTP . get ( url , params )
52+ get_link ( link , params , replacements , full_attributes )
5053 end
5154 end
5255
@@ -56,6 +59,23 @@ def combined_links
5659
5760 private
5861
62+ def forward_explore ( meth , *args )
63+ sub_id = Array ( args ) . find { |x | x . is_a? ( String ) } || ''
64+ escaped_sub_id = Addressable ::URI . encode_component ( sub_id , Addressable ::URI ::CharacterClasses ::UNRESERVED )
65+ link = "#{ @instance . id } /#{ meth } /#{ escaped_sub_id } " . chomp ( '/' )
66+ @instance . id = link
67+ LinkExplorer . new ( @links , @instance )
68+ end
69+
70+ def get_link ( link , params , replacements = [ ] , full_attributes = { } )
71+ url = replace_template_elements ( link . to_s , replacements )
72+ if link . respond_to? :media_type
73+ value_cls = LinkedData ::Client ::Base . class_for_type ( link . media_type )
74+ params [ :include ] ||= value_cls . attributes ( full_attributes )
75+ end
76+ HTTP . get ( url , params )
77+ end
78+
5979 def replace_template_elements ( url , values = [ ] )
6080 return url if values . nil? || values . empty?
6181
@@ -95,4 +115,4 @@ def linkable_attributes
95115 end
96116 end
97117 end
98- end
118+ end
0 commit comments