Class: Fcid::Consumer
- Inherits:
-
Object
- Object
- Fcid::Consumer
- Defined in:
- lib/fcid/consumer.rb
Instance Attribute Summary collapse
-
#klass ⇒ Object
Returns the value of attribute klass.
-
#token ⇒ Object
Returns the value of attribute token.
Instance Method Summary collapse
-
#initialize(token, resource_klass) ⇒ Consumer
constructor
A new instance of Consumer.
- #method_missing(method, *args) ⇒ Object
Constructor Details
#initialize(token, resource_klass) ⇒ Consumer
Returns a new instance of Consumer.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/fcid/consumer.rb', line 15 def initialize(token, resource_klass) self.token = token self.klass = Class.new(resource_klass) do @token = token @connection = Class.new(::ActiveResource::Connection) { attr_accessor :token %w( get delete head ).each do |verb| define_method verb do |*args| token.send(verb,*args) end end %w( put post ).each do |verb| define_method verb do |*args| token.send(*args) end end }.new(self.site, format) @connection.token = token end %w( element_name collection_name ).each do |attribute| self.klass.send "#{attribute}=", resource_klass.send(attribute) end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
46 47 48 |
# File 'lib/fcid/consumer.rb', line 46 def method_missing(method, *args) klass.send method, *args if klass && klass.respond_to?(method) end |
Instance Attribute Details
#klass ⇒ Object
Returns the value of attribute klass.
13 14 15 |
# File 'lib/fcid/consumer.rb', line 13 def klass @klass end |
#token ⇒ Object
Returns the value of attribute token.
13 14 15 |
# File 'lib/fcid/consumer.rb', line 13 def token @token end |