Class: Strobe::Collection
- Inherits:
-
Object
- Object
- Strobe::Collection
- Includes:
- Enumerable
- Defined in:
- lib/strobe/collection.rb
Instance Attribute Summary collapse
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #[](index) ⇒ Object
- #all ⇒ Object
- #each ⇒ Object
-
#initialize(klass, params = {}) ⇒ Collection
constructor
A new instance of Collection.
- #length ⇒ Object
- #new(params = {}) ⇒ Object
- #to_a ⇒ Object
Constructor Details
#initialize(klass, params = {}) ⇒ Collection
Returns a new instance of Collection.
7 8 9 |
# File 'lib/strobe/collection.rb', line 7 def initialize(klass, params = {}) @klass, @params = klass, params end |
Instance Attribute Details
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
5 6 7 |
# File 'lib/strobe/collection.rb', line 5 def klass @klass end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
5 6 7 |
# File 'lib/strobe/collection.rb', line 5 def params @params end |
Instance Method Details
#==(other) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/strobe/collection.rb', line 45 def ==(other) if Array === other to_a === other else super end end |
#[](index) ⇒ Object
33 34 35 |
# File 'lib/strobe/collection.rb', line 33 def [](index) to_a[index] end |
#all ⇒ Object
29 30 31 |
# File 'lib/strobe/collection.rb', line 29 def all self end |
#each ⇒ Object
25 26 27 |
# File 'lib/strobe/collection.rb', line 25 def each to_a.each { |r| yield r } end |
#length ⇒ Object
37 38 39 |
# File 'lib/strobe/collection.rb', line 37 def length to_a.length end |
#new(params = {}) ⇒ Object
41 42 43 |
# File 'lib/strobe/collection.rb', line 41 def new(params = {}) klass.new(@params.merge(params)) end |
#to_a ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/strobe/collection.rb', line 11 def to_a @to_a ||= begin resp = Strobe.connection.get klass.resource_uri, params if resp.status == 200 resp.body[klass.resource_name].map do |hash| klass.new(hash) end else raise "Something went wrong" end end end |