Class: RemoteResource::Collection
- Inherits:
-
Object
- Object
- RemoteResource::Collection
- Includes:
- Enumerable
- Defined in:
- lib/remote_resource/collection.rb
Instance Attribute Summary collapse
-
#_response ⇒ Object
readonly
Returns the value of attribute _response.
-
#meta ⇒ Object
readonly
Returns the value of attribute meta.
-
#resource_klass ⇒ Object
readonly
Returns the value of attribute resource_klass.
-
#resources_collection ⇒ Object
readonly
Returns the value of attribute resources_collection.
Instance Method Summary collapse
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(resource_klass, resources_collection, response_hash) ⇒ Collection
constructor
A new instance of Collection.
- #success? ⇒ Boolean
Constructor Details
#initialize(resource_klass, resources_collection, response_hash) ⇒ Collection
Returns a new instance of Collection.
9 10 11 12 13 14 15 |
# File 'lib/remote_resource/collection.rb', line 9 def initialize(resource_klass, resources_collection, response_hash) @resource_klass = resource_klass @resources_collection = resources_collection @response_hash = response_hash @meta = response_hash[:meta] || {} @_response = response_hash[:_response] end |
Instance Attribute Details
#_response ⇒ Object (readonly)
Returns the value of attribute _response.
7 8 9 |
# File 'lib/remote_resource/collection.rb', line 7 def _response @_response end |
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
7 8 9 |
# File 'lib/remote_resource/collection.rb', line 7 def @meta end |
#resource_klass ⇒ Object (readonly)
Returns the value of attribute resource_klass.
7 8 9 |
# File 'lib/remote_resource/collection.rb', line 7 def resource_klass @resource_klass end |
#resources_collection ⇒ Object (readonly)
Returns the value of attribute resources_collection.
7 8 9 |
# File 'lib/remote_resource/collection.rb', line 7 def resources_collection @resources_collection end |
Instance Method Details
#each(&block) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/remote_resource/collection.rb', line 17 def each(&block) if resources_collection.is_a? Array if defined?(@collection) @collection.each(&block) else @collection = [] resources_collection.each do |element| record = resource_klass.new element.merge(@response_hash) @collection << record yield(record) end end end end |
#empty? ⇒ Boolean
32 33 34 |
# File 'lib/remote_resource/collection.rb', line 32 def empty? resources_collection.blank? end |
#success? ⇒ Boolean
36 37 38 |
# File 'lib/remote_resource/collection.rb', line 36 def success? _response.success? end |