Class: Sitepress::Models::Collection

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#globObject (readonly)

Returns the value of attribute glob.



14
15
16
# File 'lib/sitepress/models/collection.rb', line 14

def glob
  @glob
end

#modelObject (readonly)

Returns the value of attribute model.



14
15
16
# File 'lib/sitepress/models/collection.rb', line 14

def model
  @model
end

#siteObject (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

#eachObject

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

#resourcesObject



22
23
24
# File 'lib/sitepress/models/collection.rb', line 22

def resources
  site.glob glob
end