Class: Nanoc::Core::ConfigView

Inherits:
View
  • Object
show all
Defined in:
lib/nanoc/core/config_view.rb

Direct Known Subclasses

MutableConfigView

Instance Method Summary collapse

Methods inherited from View

#_context, #frozen?, #inspect

Methods included from ContractsSupport

enabled?, included, setup_once, warn_about_performance

Constructor Details

#initialize(config, context) ⇒ ConfigView

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of ConfigView.



7
8
9
10
# File 'lib/nanoc/core/config_view.rb', line 7

def initialize(config, context)
  super(context)
  @config = config
end

Instance Method Details

#[](key) ⇒ Object

See Also:

  • Hash#[]


43
44
45
46
# File 'lib/nanoc/core/config_view.rb', line 43

def [](key)
  @context.dependency_tracker.bounce(_unwrap, attributes: [key])
  @config[key]
end

#_unwrapObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



13
14
15
# File 'lib/nanoc/core/config_view.rb', line 13

def _unwrap
  @config
end

#dig(*keys) ⇒ Object

See Also:

  • Hash#dig


61
62
63
64
# File 'lib/nanoc/core/config_view.rb', line 61

def dig(*keys)
  @context.dependency_tracker.bounce(_unwrap, attributes: keys.take(1))
  @config.dig(*keys)
end

#each(&block) ⇒ Object

See Also:

  • Hash#each


49
50
51
52
# File 'lib/nanoc/core/config_view.rb', line 49

def each(&block)
  @context.dependency_tracker.bounce(_unwrap, attributes: true)
  @config.each(&block)
end

#env_nameObject



55
56
57
58
# File 'lib/nanoc/core/config_view.rb', line 55

def env_name
  @context.dependency_tracker.bounce(_unwrap, attributes: true)
  @config.env_name
end

#fetch(key, fallback = Nanoc::Core::UNDEFINED, &_block) ⇒ Object

See Also:

  • Hash#fetch


23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/nanoc/core/config_view.rb', line 23

def fetch(key, fallback = Nanoc::Core::UNDEFINED, &_block)
  @context.dependency_tracker.bounce(_unwrap, attributes: [key])
  @config.fetch(key) do
    if !Nanoc::Core::UNDEFINED.equal?(fallback)
      fallback
    elsif block_given?
      yield(key)
    else
      raise KeyError, "key not found: #{key.inspect}"
    end
  end
end

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)

See Also:

  • Hash#key?


37
38
39
40
# File 'lib/nanoc/core/config_view.rb', line 37

def key?(key)
  @context.dependency_tracker.bounce(_unwrap, attributes: [key])
  @config.key?(key)
end

#output_dirObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



18
19
20
# File 'lib/nanoc/core/config_view.rb', line 18

def output_dir
  @config.output_dir
end