Class: Drip::Collection
- Inherits:
-
Object
show all
- Includes:
- Enumerable
- Defined in:
- lib/drip/collection.rb
Direct Known Subclasses
Accounts, Broadcasts, CampaignSubscriptions, Campaigns, Errors, Orders, Purchases, Subscribers, Tags, Webhooks, WorkflowTriggers, Workflows
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(raw_items) ⇒ Collection
Returns a new instance of Collection.
9
10
11
12
|
# File 'lib/drip/collection.rb', line 9
def initialize(raw_items)
@raw_items = raw_items.dup.freeze
@items = parse_items
end
|
Instance Attribute Details
#items ⇒ Object
Returns the value of attribute items.
7
8
9
|
# File 'lib/drip/collection.rb', line 7
def items
@items
end
|
#raw_items ⇒ Object
Returns the value of attribute raw_items.
7
8
9
|
# File 'lib/drip/collection.rb', line 7
def raw_items
@raw_items
end
|
Class Method Details
.collection_name ⇒ Object
14
15
16
|
# File 'lib/drip/collection.rb', line 14
def self.collection_name
"resources"
end
|
.resource_name ⇒ Object
18
19
20
|
# File 'lib/drip/collection.rb', line 18
def self.resource_name
"resource"
end
|
Instance Method Details
#each(&block) ⇒ Object
37
38
39
|
# File 'lib/drip/collection.rb', line 37
def each(&block)
items.each { |item| yield(item) }
end
|
#item_class ⇒ Object
22
23
24
25
|
# File 'lib/drip/collection.rb', line 22
def item_class
@item_class ||= Drip::Resources.
find_class(self.class.resource_name)
end
|
#parse_items ⇒ Object
27
28
29
30
31
|
# File 'lib/drip/collection.rb', line 27
def parse_items
raw_items.map do |raw_item|
raw_item.is_a?(String) ? raw_item : item_class.new(raw_item)
end
end
|
#singular? ⇒ Boolean
33
34
35
|
# File 'lib/drip/collection.rb', line 33
def singular?
items.length < 2
end
|