Class: JSON_ROA::Client::Collection
- Inherits:
-
Object
- Object
- JSON_ROA::Client::Collection
- Includes:
- Enumerable
- Defined in:
- lib/json_roa/client/collection.rb
Instance Attribute Summary collapse
-
#conn ⇒ Object
readonly
Returns the value of attribute conn.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
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.
10 11 12 13 |
# File 'lib/json_roa/client/collection.rb', line 10 def initialize(conn, resource) @conn = conn @resource = resource end |
Instance Attribute Details
#conn ⇒ Object (readonly)
Returns the value of attribute conn.
7 8 9 |
# File 'lib/json_roa/client/collection.rb', line 7 def conn @conn end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
8 9 10 |
# File 'lib/json_roa/client/collection.rb', line 8 def resource @resource end |
Instance Method Details
#collection_data ⇒ Object
35 36 37 |
# File 'lib/json_roa/client/collection.rb', line 35 def collection_data @resource.json_roa_data['collection'] end |
#each(&_block) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/json_roa/client/collection.rb', line 15 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
39 40 41 |
# File 'lib/json_roa/client/collection.rb', line 39 def to_s "#{self.class.name}: #{collection_data}" end |