Class: WaxTasks::Config
- Inherits:
-
Object
- Object
- WaxTasks::Config
- Defined in:
- lib/wax_tasks/config.rb
Instance Attribute Summary collapse
-
#collections ⇒ Object
readonly
Returns the value of attribute collections.
Instance Method Summary collapse
- #collections_dir ⇒ Object
-
#ext ⇒ String
Contructs permalink extension from site ‘permalink` variable.
- #find_collection(name) ⇒ Object
-
#initialize(config) ⇒ Config
constructor
A new instance of Config.
- #process_collections ⇒ Object
- #search(name) ⇒ Object
- #source ⇒ Object
Constructor Details
#initialize(config) ⇒ Config
Returns a new instance of Config.
8 9 10 11 |
# File 'lib/wax_tasks/config.rb', line 8 def initialize(config) @config = config @collections = process_collections end |
Instance Attribute Details
#collections ⇒ Object (readonly)
Returns the value of attribute collections.
6 7 8 |
# File 'lib/wax_tasks/config.rb', line 6 def collections @collections end |
Instance Method Details
#collections_dir ⇒ Object
21 22 23 |
# File 'lib/wax_tasks/config.rb', line 21 def collections_dir @config.dig 'collections_dir' end |
#ext ⇒ String
Contructs permalink extension from site ‘permalink` variable
29 30 31 32 33 34 35 36 |
# File 'lib/wax_tasks/config.rb', line 29 def ext case @config.dig 'permalink' when 'pretty' || '/' '/' else '.html' end end |
#find_collection(name) ⇒ Object
68 69 70 71 72 73 |
# File 'lib/wax_tasks/config.rb', line 68 def find_collection(name) collection = @collections.find { |c| c.name == name } raise WaxTasks::Error::InvalidCollection, "Cannot find requested collection '#{name}'" if collection.nil? collection end |
#process_collections ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/wax_tasks/config.rb', line 40 def process_collections if @config.key? 'collections' @config['collections'].map do |k, v| WaxTasks::Collection.new(k, v, source, collections_dir, ext) end else [] end end |
#search(name) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/wax_tasks/config.rb', line 52 def search(name) search_config = @config.dig 'search', name raise WaxTasks::Error::InvalidConfig if search_config.nil? raise WaxTasks::Error::InvalidConfig unless search_config.dig('collections').is_a? Hash search_config['collections'] = search_config['collections'].map do |k, v| fields = v.fetch('fields', []) fields << 'content' if v.fetch('content', false) find_collection(k).tap { |c| c.search_fields = fields } end search_config end |
#source ⇒ Object
15 16 17 |
# File 'lib/wax_tasks/config.rb', line 15 def source @config.dig 'source' end |