Class: ApiResource::ResourceCollection
- Inherits:
-
Object
- Object
- ApiResource::ResourceCollection
- Includes:
- Enumerable
- Defined in:
- lib/api-resource/resource.rb
Instance Attribute Summary collapse
-
#raw_result ⇒ Object
readonly
Returns the value of attribute raw_result.
Instance Method Summary collapse
- #acts_like_array? ⇒ Boolean
-
#initialize(data, meta, klass, raw_result = nil) ⇒ ResourceCollection
constructor
A new instance of ResourceCollection.
- #method_missing(m, *args, &block) ⇒ Object
- #respond_to_missing?(m, _) ⇒ Boolean
Constructor Details
#initialize(data, meta, klass, raw_result = nil) ⇒ ResourceCollection
Returns a new instance of ResourceCollection.
315 316 317 318 319 |
# File 'lib/api-resource/resource.rb', line 315 def initialize(data, , klass, raw_result=nil) .each { |k, v| self.class.class_eval { define_method(k) { v } } } if @resources = data.map { |e| klass.new(e) }.to_a @raw_result = raw_result end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
321 322 323 324 325 326 327 |
# File 'lib/api-resource/resource.rb', line 321 def method_missing(m, *args, &block) if @resources.respond_to?(m) @resources.send(m,*args, &block) else super end end |
Instance Attribute Details
#raw_result ⇒ Object (readonly)
Returns the value of attribute raw_result.
313 314 315 |
# File 'lib/api-resource/resource.rb', line 313 def raw_result @raw_result end |
Instance Method Details
#acts_like_array? ⇒ Boolean
333 334 |
# File 'lib/api-resource/resource.rb', line 333 def acts_like_array? end |
#respond_to_missing?(m, _) ⇒ Boolean
329 330 331 |
# File 'lib/api-resource/resource.rb', line 329 def respond_to_missing?(m, _) @resources.respond_to?(m) end |