Class: Pivotal::Collection

Inherits:
Object
  • Object
show all
Defined in:
lib/pivotal/collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_classObject

Returns the value of attribute component_class.



6
7
8
# File 'lib/pivotal/collection.rb', line 6

def component_class
  @component_class
end

#resourceObject

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

#firstObject



25
26
27
# File 'lib/pivotal/collection.rb', line 25

def first
  all.first
end