class Nanoc::Int::Configuration

Represents the site configuration.

@api private

Constants

DEFAULT_CONFIG

The default configuration for a site. A site's configuration overrides these options: when a {Nanoc::Int::Site} is created with a configuration that lacks some options, the default value will be taken from `DEFAULT_CONFIG`.

DEFAULT_DATA_SOURCE_CONFIG

The default configuration for a data source. A data source's configuration overrides these options.

NONE

Public Class Methods

new(hash = {}) click to toggle source

Creates a new configuration with the given hash.

@param [Hash] hash The actual configuration hash

# File lib/nanoc/base/entities/configuration.rb, line 37
def initialize(hash = {})
  @wrapped = hash.__nanoc_symbolize_keys_recursively
end

Public Instance Methods

[](key) click to toggle source
# File lib/nanoc/base/entities/configuration.rb, line 58
def [](key)
  @wrapped[key]
end
[]=(key, value) click to toggle source
# File lib/nanoc/base/entities/configuration.rb, line 74
def []=(key, value)
  @wrapped[key] = value
end
each() { |k, v| ... } click to toggle source
# File lib/nanoc/base/entities/configuration.rb, line 90
def each
  @wrapped.each { |k, v| yield(k, v) }
  self
end
fetch(key, fallback = NONE) { |key| ... } click to toggle source
# File lib/nanoc/base/entities/configuration.rb, line 62
def fetch(key, fallback = NONE, &_block)
  @wrapped.fetch(key) do
    if !fallback.equal?(NONE)
      fallback
    elsif block_given?
      yield(key)
    else
      raise KeyError, "key not found: #{key.inspect}"
    end
  end
end
freeze() click to toggle source
Calls superclass method
# File lib/nanoc/base/entities/configuration.rb, line 95
def freeze
  super
  @wrapped.__nanoc_freeze_recursively
end
inspect() click to toggle source
# File lib/nanoc/base/entities/configuration.rb, line 107
def inspect
  "<#{self.class}>"
end
key?(key) click to toggle source
# File lib/nanoc/base/entities/configuration.rb, line 54
def key?(key)
  @wrapped.key?(key)
end
merge(hash) click to toggle source
# File lib/nanoc/base/entities/configuration.rb, line 78
def merge(hash)
  self.class.new(@wrapped.merge(hash.to_h))
end
reference() click to toggle source

Returns an object that can be used for uniquely identifying objects.

@return [Object] An unique reference to this object

# File lib/nanoc/base/entities/configuration.rb, line 103
def reference
  :config
end
to_h() click to toggle source
# File lib/nanoc/base/entities/configuration.rb, line 50
def to_h
  @wrapped
end
update(hash) click to toggle source
# File lib/nanoc/base/entities/configuration.rb, line 86
def update(hash)
  @wrapped.update(hash)
end
with_defaults() click to toggle source
# File lib/nanoc/base/entities/configuration.rb, line 41
def with_defaults
  new_wrapped = DEFAULT_CONFIG.merge(@wrapped)
  new_wrapped[:data_sources] = new_wrapped[:data_sources].map do |ds|
    DEFAULT_DATA_SOURCE_CONFIG.merge(ds)
  end

  self.class.new(new_wrapped)
end
without(key) click to toggle source
# File lib/nanoc/base/entities/configuration.rb, line 82
def without(key)
  self.class.new(@wrapped.reject { |k, _v| k == key })
end