Class: Slugforge::Configuration
- Inherits:
-
Object
- Object
- Slugforge::Configuration
- 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
-
.configuration_files ⇒ Object
Returns the value of attribute configuration_files.
Instance Attribute Summary collapse
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Class Method Summary collapse
Instance Method Summary collapse
- #activate_slugins ⇒ Object
-
#defaults ⇒ Object
Get a hash of all options with default values.
-
#initialize(options = {}) ⇒ Configuration
constructor
A new instance of Configuration.
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( = {}) @slugin_manager = SluginManager.new self.load end |
Class Attribute Details
.configuration_files ⇒ Object
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
#values ⇒ Object (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 .key?(name) [name] = config define_method(name) { values[name] } end |
.options ⇒ Object
23 24 25 |
# File 'lib/slugforge/configuration.rb', line 23 def @options ||= {} end |
Instance Method Details
#activate_slugins ⇒ Object
62 63 64 |
# File 'lib/slugforge/configuration.rb', line 62 def activate_slugins @slugin_manager.activate_slugins(self) unless disable_slugins end |
#defaults ⇒ Object
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..select { |_, c| c.key?(:default) }.map { |n,c| [n, c[:default]] }].merge(@values) end |