Class: JSON_ROA::Client::Collection
- Inherits:
-
Object
- Object
- JSON_ROA::Client::Collection
- Includes:
- Enumerable
- Defined in:
- lib/json_roa/client/collection.rb
Instance Method Summary collapse
- #collection_data ⇒ Object
- #each(&_block) ⇒ Object
-
#initialize(conn, resource) ⇒ Collection
constructor
A new instance of Collection.
- #to_s ⇒ Object
Constructor Details
#initialize(conn, resource) ⇒ Collection
Returns a new instance of Collection.
7 8 9 10 |
# File 'lib/json_roa/client/collection.rb', line 7 def initialize(conn, resource) @conn = conn @resource = resource end |
Instance Method Details
#collection_data ⇒ Object
32 33 34 |
# File 'lib/json_roa/client/collection.rb', line 32 def collection_data @resource.json_roa_data['collection'] end |
#each(&_block) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/json_roa/client/collection.rb', line 12 def each(&_block) loop do relations = collection_data['relations'] rescue [] relations.each do |key, data| yield Relation.new(@conn, key, data) if block_given? end next_val = collection_data['next'] rescue nil if relations.empty? or (not next_val) break else @resource = Relation.new(@conn, 'next', next_val).get end end end |
#to_s ⇒ Object
36 37 38 |
# File 'lib/json_roa/client/collection.rb', line 36 def to_s "#{self.class.name}: #{collection_data}" end |