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.
Constant Summary collapse
- DEFAULT_NAME =
Page models will have ‘PageModel.all` method defined by default.
:all
- DEFAULT_GLOB =
Iterate over all resources in the site by default.
"**/*.*".freeze
Instance Attribute Summary collapse
-
#glob ⇒ Object
readonly
Returns the value of attribute glob.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#site ⇒ Object
readonly
Returns the value of attribute site.
Instance Method Summary collapse
-
#each ⇒ Object
Wraps each resource in a model object.
-
#initialize(model:, site:, glob: DEFAULT_GLOB) ⇒ Collection
constructor
A new instance of Collection.
- #resources ⇒ Object
Constructor Details
#initialize(model:, site:, glob: DEFAULT_GLOB) ⇒ Collection
Returns a new instance of Collection.
16 17 18 19 20 |
# File 'lib/sitepress/models/collection.rb', line 16 def initialize(model:, site:, glob: DEFAULT_GLOB) @model = model @glob = glob @site = site end |
Instance Attribute Details
#glob ⇒ Object (readonly)
Returns the value of attribute glob.
14 15 16 |
# File 'lib/sitepress/models/collection.rb', line 14 def glob @glob end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
14 15 16 |
# File 'lib/sitepress/models/collection.rb', line 14 def model @model end |
#site ⇒ Object (readonly)
Returns the value of attribute site.
14 15 16 |
# File 'lib/sitepress/models/collection.rb', line 14 def site @site end |
Instance Method Details
#each ⇒ Object
Wraps each resource in a model object.
27 28 29 30 31 |
# File 'lib/sitepress/models/collection.rb', line 27 def each resources.each do |resource| yield model.new resource end end |
#resources ⇒ Object
22 23 24 |
# File 'lib/sitepress/models/collection.rb', line 22 def resources site.glob glob end |