Class: Pivotal::Collection
- Inherits:
-
Object
- Object
- Pivotal::Collection
- Defined in:
- lib/pivotal/collection.rb
Instance Attribute Summary collapse
-
#component_class ⇒ Object
Returns the value of attribute component_class.
-
#resource ⇒ Object
Returns the value of attribute resource.
Instance Method Summary collapse
-
#find(*args) ⇒ Object
Param queries will break our REST structure, so if we find an :id parameter, accept it and ignore all other params.
- #first ⇒ Object
-
#initialize(resource, component_class) ⇒ Collection
constructor
A new instance of Collection.
Constructor Details
#initialize(resource, component_class) ⇒ Collection
Returns a new instance of Collection.
8 9 10 |
# File 'lib/pivotal/collection.rb', line 8 def initialize(resource, component_class) @resource, @component_class = resource, component_class end |
Instance Attribute Details
#component_class ⇒ Object
Returns the value of attribute component_class.
6 7 8 |
# File 'lib/pivotal/collection.rb', line 6 def component_class @component_class end |
#resource ⇒ Object
Returns the value of attribute resource.
6 7 8 |
# File 'lib/pivotal/collection.rb', line 6 def resource @resource end |
Instance Method Details
#find(*args) ⇒ Object
Param queries will break our REST structure, so if we find an :id parameter, accept it and ignore all other params.
15 16 17 18 19 20 21 22 23 |
# File 'lib/pivotal/collection.rb', line 15 def find(*args) params = args.last.is_a?(Hash) ? args.pop : {} finder = args.first return item(params[:id]) if params[:id] return item(finder) if finder.is_a?(Numeric) all(params) end |
#first ⇒ Object
25 26 27 |
# File 'lib/pivotal/collection.rb', line 25 def first all.first end |