Class: Slugforge::Configuration

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/slugforge/configuration.rb

Overview

Handles loading configuration data from files and the environment. Order of precedence:

1) ENV 2) ‘pwd`/.slugforge 3) $HOME/.slugforge 4) /etc/slugforge

We load in reverse order, allowing us to simply overwrite values whenever found.

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Configuration

Returns a new instance of Configuration.



49
50
51
52
53
# File 'lib/slugforge/configuration.rb', line 49

def initialize(options = {})
  @slugin_manager = SluginManager.new
  self.load
  update_from_options options
end

Class Attribute Details

.configuration_filesObject

Returns the value of attribute configuration_files.



18
19
20
# File 'lib/slugforge/configuration.rb', line 18

def configuration_files
  @configuration_files
end

Instance Attribute Details

#valuesObject (readonly)

Returns the value of attribute values.



47
48
49
# File 'lib/slugforge/configuration.rb', line 47

def values
  @values
end

Class Method Details

.option(name, config) ⇒ Object



27
28
29
30
31
32
# File 'lib/slugforge/configuration.rb', line 27

def option(name, config)
  raise "configuration option #{name} has already been defined" if options.key?(name)

  options[name] = config
  define_method(name) { values[name] }
end

.optionsObject



23
24
25
# File 'lib/slugforge/configuration.rb', line 23

def options
  @options ||= {}
end

Instance Method Details

#activate_sluginsObject



62
63
64
# File 'lib/slugforge/configuration.rb', line 62

def activate_slugins
  @slugin_manager.activate_slugins(self) unless disable_slugins
end

#defaultsObject

Get a hash of all options with default values. The list of values is initialized with the result.



58
59
60
# File 'lib/slugforge/configuration.rb', line 58

def defaults
  @values = Hash[self.class.options.select { |_, c| c.key?(:default) }.map { |n,c| [n, c[:default]] }].merge(@values)
end