Class: Sitepress::Models::Collection
- Inherits:
-
Object
- Object
- Sitepress::Models::Collection
- Includes:
- Enumerable
- Defined in:
- lib/sitepress/models/collection.rb
Overview
Everything needed to iterate over a set of resources from a glob and wrap them in a model so they are returned as a sensible enumerable.
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
-
#each(&block) ⇒ Object
Wraps each resource in a model object.
-
#initialize(model:, &resources) ⇒ Collection
constructor
A new instance of Collection.
- #resources ⇒ Object
Constructor Details
#initialize(model:, &resources) ⇒ Collection
Returns a new instance of Collection.
10 11 12 13 |
# File 'lib/sitepress/models/collection.rb', line 10 def initialize(model:, &resources) @model = model @resources = resources end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
8 9 10 |
# File 'lib/sitepress/models/collection.rb', line 8 def model @model end |
Instance Method Details
#each(&block) ⇒ Object
Wraps each resource in a model object.
20 21 22 23 24 25 26 |
# File 'lib/sitepress/models/collection.rb', line 20 def each(&block) return to_enum(:each) unless block_given? resources.each do |resource| yield model.new(resource) end end |
#resources ⇒ Object
15 16 17 |
# File 'lib/sitepress/models/collection.rb', line 15 def resources @resources.call end |