Class: Consumer::Proxy

Inherits:
Hash
  • Object
show all
Defined in:
lib/consumer/proxy.rb

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Proxy

Returns a new instance of Proxy.



4
5
6
# File 'lib/consumer/proxy.rb', line 4

def initialize(hash)
  hash.each { |k, v| self[k.to_s] = v }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



8
9
10
11
12
# File 'lib/consumer/proxy.rb', line 8

def method_missing(method, *args, &block)
  _method = method.to_s
  super if args.any? or not respond_to?(_method)
  return methodize_me(self[_method])
end

Instance Method Details



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

def link(rel = nil)
  return method_missing(:link) if rel.nil?

  _link = self["link"] || self["links"]
  _link = [_link].flatten
  _link = _link.find {|l| l.is_a?(Hash) and l["rel"] == rel }

  methodize_me(_link)
end

#respond_to?(method) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/consumer/proxy.rb', line 24

def respond_to?(method)
  self.has_key?(method.to_s) or super
end