Sha256: 9ede161a6a2ff356fdd8a0d75b442896535d45d68c9be927a83c95d78ae1051a

Contents?: true

Size: 782 Bytes

Versions: 48

Compression:

Stored size: 782 Bytes

Contents

module Nanoc
  class ConfigView < ::Nanoc::View
    # @api private
    NONE = Object.new.freeze

    # @api private
    def initialize(config, context)
      super(context)
      @config = config
    end

    # @api private
    def unwrap
      @config
    end

    # @see Hash#fetch
    def fetch(key, fallback = NONE, &_block)
      @config.fetch(key) do
        if !fallback.equal?(NONE)
          fallback
        elsif block_given?
          yield(key)
        else
          raise KeyError, "key not found: #{key.inspect}"
        end
      end
    end

    # @see Hash#key?
    def key?(key)
      @config.key?(key)
    end

    # @see Hash#[]
    def [](key)
      @config[key]
    end

    # @see Hash#each
    def each(&block)
      @config.each(&block)
    end
  end
end

Version data entries

48 entries across 48 versions & 1 rubygems

Version Path
nanoc-4.7.9 lib/nanoc/base/views/config_view.rb
nanoc-4.7.8 lib/nanoc/base/views/config_view.rb
nanoc-4.7.7 lib/nanoc/base/views/config_view.rb
nanoc-4.7.6 lib/nanoc/base/views/config_view.rb
nanoc-4.7.5 lib/nanoc/base/views/config_view.rb
nanoc-4.7.4 lib/nanoc/base/views/config_view.rb
nanoc-4.7.3 lib/nanoc/base/views/config_view.rb
nanoc-4.7.2 lib/nanoc/base/views/config_view.rb
nanoc-4.7.1 lib/nanoc/base/views/config_view.rb
nanoc-4.7.0 lib/nanoc/base/views/config_view.rb
nanoc-4.6.4 lib/nanoc/base/views/config_view.rb
nanoc-4.6.3 lib/nanoc/base/views/config_view.rb
nanoc-4.6.2 lib/nanoc/base/views/config_view.rb
nanoc-4.6.1 lib/nanoc/base/views/config_view.rb
nanoc-4.6.0 lib/nanoc/base/views/config_view.rb
nanoc-4.5.4 lib/nanoc/base/views/config_view.rb
nanoc-4.5.3 lib/nanoc/base/views/config_view.rb
nanoc-4.5.2 lib/nanoc/base/views/config_view.rb
nanoc-4.5.1 lib/nanoc/base/views/config_view.rb
nanoc-4.5.0 lib/nanoc/base/views/config_view.rb