Class: LinkedData::Client::LinkExplorer

Inherits:
Object
  • Object
show all
Defined in:
lib/ontologies_api_client/link_explorer.rb

Constant Summary collapse

HTTP =
LinkedData::Client::HTTP

Instance Method Summary collapse

Constructor Details

#initialize(links, instance) ⇒ LinkExplorer

Returns a new instance of LinkExplorer.



9
10
11
12
# File 'lib/ontologies_api_client/link_explorer.rb', line 9

def initialize(links, instance)
  @links = links
  @instance = instance
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/ontologies_api_client/link_explorer.rb', line 14

def method_missing(meth, *args, &block)
  if combined_links.key?(meth.to_s)
    explore_link(meth, *args)
  elsif meth == :batch
    explore_link(args)
  else
    super
  end
end

Instance Method Details



53
54
55
# File 'lib/ontologies_api_client/link_explorer.rb', line 53

def combined_links
  linkable_attributes.merge(@links)
end


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/ontologies_api_client/link_explorer.rb', line 32

def explore_link(*args)
  link = combined_links[args.shift.to_s]
  params = args.shift
  unless params.is_a?(Hash)
    args.push(params)
    params = {}
  end
  replacements = args.shift
  full_attributes = params.delete(:full)
  if link.is_a?(Array)
    value_cls = LinkedData::Client::Base.class_for_type(link.first.media_type)
    ids = link.map {|l| l.to_s}
    value_cls.where {|o| ids.include?(o.id)}
  else
    url = replace_template_elements(link.to_s, replacements)
    value_cls = LinkedData::Client::Base.class_for_type(link.media_type)
    params[:include] ||= value_cls.attributes(full_attributes)
    HTTP.get(url, params)
  end
end

#respond_to?(meth, private = false) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
27
28
29
30
# File 'lib/ontologies_api_client/link_explorer.rb', line 24

def respond_to?(meth, private = false)
  if combined_links.key?(meth.to_s) || meth == :batch
    return true
  else
    super
  end
end