Class: WaxTasks::Collection
- Inherits:
-
Object
- Object
- WaxTasks::Collection
- Defined in:
- lib/wax_tasks/collection.rb
Overview
Parent class representing a Jekyll collection that cannot be created directly. Only child classes (IiifCollection, LunrCollection, PagemasterCollection) can be initialized.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#config ⇒ Hash
the collection config within site config.
-
#name ⇒ String
the name of the collection in site:collections.
-
#page_dir ⇒ String
the directory path for generated collection pages.
-
#site ⇒ Hash
the site config.
Class Method Summary collapse
-
.inherited ⇒ Object
This method ensures child classes can be instantiated though Collection.new cannot be.
Instance Method Summary collapse
-
#collection_config ⇒ Hash
Finds the collection config within the site config.
-
#ingest_file(source) ⇒ Array
Ingests the collection source data as an Array of Hashes.
-
#initialize(name, site) ⇒ Collection
constructor
Creates a new collection with name @name given site config @site.
Constructor Details
#initialize(name, site) ⇒ Collection
Creates a new collection with name @name given site config @site
25 26 27 28 29 30 31 32 |
# File 'lib/wax_tasks/collection.rb', line 25 def initialize(name, site) @name = name @site = site @config = collection_config @page_dir = Utils.make_path(@site[:source_dir], @site[:collections_dir], "_#{@name}") end |
Instance Attribute Details
#config ⇒ Hash
the collection config within site config
11 12 13 |
# File 'lib/wax_tasks/collection.rb', line 11 def config @config end |
#name ⇒ String
the name of the collection in site:collections
11 12 13 |
# File 'lib/wax_tasks/collection.rb', line 11 def name @name end |
#page_dir ⇒ String
the directory path for generated collection pages
11 12 13 |
# File 'lib/wax_tasks/collection.rb', line 11 def page_dir @page_dir end |
#site ⇒ Hash
the site config
11 12 13 |
# File 'lib/wax_tasks/collection.rb', line 11 def site @site end |
Class Method Details
.inherited ⇒ Object
This method ensures child classes can be instantiated though Collection.new cannot be.
17 18 19 |
# File 'lib/wax_tasks/collection.rb', line 17 def self.inherited(*) public_class_method :new end |
Instance Method Details
#collection_config ⇒ Hash
Finds the collection config within the site config
37 38 39 40 41 |
# File 'lib/wax_tasks/collection.rb', line 37 def collection_config @site[:collections].fetch(@name) rescue StandardError => e raise Error::InvalidCollection, "Cannot load collection config for #{@name}.\n#{e}" end |
#ingest_file(source) ⇒ Array
Ingests the collection source data as an Array of Hashes
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/wax_tasks/collection.rb', line 47 def ingest_file(source) raise Error::MissingSource, "Cannot find #{source}" unless File.exist? source data = case File.extname(source) when '.csv' WaxTasks::Utils.validate_csv(source) when '.json' WaxTasks::Utils.validate_json(source) when /\.ya?ml/ WaxTasks::Utils.validate_yaml(source) else raise Error::InvalidSource, "Can't load #{File.extname(source)} files. Culprit: #{source}" end WaxTasks::Utils.assert_pids(data) WaxTasks::Utils.assert_unique(data) end |