Class: Round::Collection
- Inherits:
-
Base
- Object
- Base
- Round::Collection
show all
- Includes:
- Enumerable
- Defined in:
- lib/round/collection.rb
Instance Attribute Summary collapse
Attributes inherited from Base
#resource
Instance Method Summary
collapse
Methods inherited from Base
association, hash_identifier, #hash_identifier
Constructor Details
#initialize(options = {}, &block) ⇒ Collection
Returns a new instance of Collection.
6
7
8
9
10
|
# File 'lib/round/collection.rb', line 6
def initialize(options = {}, &block)
super(options)
options.delete(:resource)
populate_data(options, &block)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
45
46
47
48
49
|
# File 'lib/round/collection.rb', line 45
def method_missing(meth, *args, &block)
@collection.send(meth, *args, &block)
rescue
super
end
|
Instance Attribute Details
#collection ⇒ Object
Returns the value of attribute collection.
4
5
6
|
# File 'lib/round/collection.rb', line 4
def collection
@collection
end
|
Instance Method Details
#[](key) ⇒ Object
37
38
39
40
41
42
43
|
# File 'lib/round/collection.rb', line 37
def [](key)
if key.is_a?(Fixnum)
@collection[key]
else
@hash[key]
end
end
|
#add(content) ⇒ Object
28
29
30
31
|
# File 'lib/round/collection.rb', line 28
def add(content)
@collection << content
@hash[content.hash_identifier] = content
end
|
#content_type ⇒ Object
33
34
35
|
# File 'lib/round/collection.rb', line 33
def content_type
Round::Base
end
|
#populate_data(options = {}, &block) ⇒ Object
12
13
14
15
16
17
18
19
20
|
# File 'lib/round/collection.rb', line 12
def populate_data(options = {}, &block)
@collection = []
@hash = {}
@resource.list.each do |resource|
content = self.content_type.new(options.merge(resource: resource, client: @client))
yield content if block
self.add(content)
end if @resource.list rescue nil
end
|
#refresh(options = {}) ⇒ Object
22
23
24
25
26
|
# File 'lib/round/collection.rb', line 22
def refresh(options = {})
@collection = []
populate_data(options)
self
end
|