Class: Cottontail::Configurable::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/cottontail/configurable.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(parent = nil) ⇒ Configuration

Returns a new instance of Configuration.



35
36
37
38
39
40
41
# File 'lib/cottontail/configurable.rb', line 35

def initialize(parent = nil)
  reset!

  if parent.kind_of?(Cottontail::Configuration)
    parent.each { |k, v| set(k, v) }
  end
end

Instance Method Details

#each(&block) ⇒ Object



66
67
68
# File 'lib/cottontail/configurable.rb', line 66

def each(&block)
  @settings.each(&block)
end

#get(key) ⇒ Object

Get a configuration option. It will be evalued of the first time of calling.

Examples:

get :logger


57
58
59
60
61
62
63
# File 'lib/cottontail/configurable.rb', line 57

def get(key)
  if (value = @settings[key]).is_a?(Proc)
    @settings[key] = value.call
  end

  @settings[key]
end

#inheritable_copyObject



71
72
73
# File 'lib/cottontail/configurable.rb', line 71

def inheritable_copy
  self.class.new(self)
end

#reset!Object



76
77
78
# File 'lib/cottontail/configurable.rb', line 76

def reset!
  @settings = {}
end

#set(key, value = nil, &block) ⇒ Object

Set a configuration option.

Examples:

set :logger, Yell.new($stdout)
set :logger, -> { Yell.new($stdout) }


48
49
50
# File 'lib/cottontail/configurable.rb', line 48

def set(key, value = nil, &block)
  @settings[key] = block.nil? ? value : block
end