Class: CiscoSpark::Collection

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model_klass, collection = [], response = nil) ⇒ Collection

Returns a new instance of Collection.



5
6
7
8
9
10
# File 'lib/cisco_spark/collection.rb', line 5

def initialize(model_klass, collection=[], response=nil)
  @model_klass = model_klass
  @collection = collection

  parse_pagination(response)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/cisco_spark/collection.rb', line 12

def method_missing(name, *args, &block)
  if collection.respond_to?(name)
    collection.send(name, *args, &block)
  else
    super
  end
end

Instance Attribute Details

#collectionObject

Returns the value of attribute collection.



3
4
5
# File 'lib/cisco_spark/collection.rb', line 3

def collection
  @collection
end

#model_klassObject

Returns the value of attribute model_klass.



3
4
5
# File 'lib/cisco_spark/collection.rb', line 3

def model_klass
  @model_klass
end

Instance Method Details

#nextObject



20
21
22
23
24
25
26
# File 'lib/cisco_spark/collection.rb', line 20

def next
  return false unless next_params
  response = model_klass.fetch_all_raw(next_params)
  @collection = model_klass.parse_collection(response.body)
  parse_pagination(response)
  self
end