Class: Vayacondios::Configuration
- Inherits:
-
Object
- Object
- Vayacondios::Configuration
- Defined in:
- lib/vayacondios/configuration.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#base_filename ⇒ Object
Returns the value of attribute base_filename.
-
#load_order ⇒ Object
Returns the value of attribute load_order.
Instance Method Summary collapse
- #[](handle) ⇒ Object
- #apply_all ⇒ Object
- #defaults ⇒ Object
- #global ⇒ Object
-
#initialize(base_fname = nil) ⇒ Configuration
constructor
A new instance of Configuration.
- #overlay(conf = nil) ⇒ Object
- #project ⇒ Object
- #resolve! ⇒ Object
- #resolved? ⇒ Boolean
- #resolved_settings ⇒ Object
Constructor Details
#initialize(base_fname = nil) ⇒ Configuration
Returns a new instance of Configuration.
6 7 8 9 10 |
# File 'lib/vayacondios/configuration.rb', line 6 def initialize(base_fname = nil) @base_filename = base_fname || 'vayacondios.yml' @load_order = %w[ global project ] @settings = Configliere::Param.new end |
Instance Attribute Details
#base_filename ⇒ Object
Returns the value of attribute base_filename.
4 5 6 |
# File 'lib/vayacondios/configuration.rb', line 4 def base_filename @base_filename end |
#load_order ⇒ Object
Returns the value of attribute load_order.
4 5 6 |
# File 'lib/vayacondios/configuration.rb', line 4 def load_order @load_order end |
Instance Method Details
#[](handle) ⇒ Object
38 39 40 |
# File 'lib/vayacondios/configuration.rb', line 38 def [] handle resolved_settings[handle.to_sym] end |
#apply_all ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/vayacondios/configuration.rb', line 42 def apply_all scopes = load_order.dup.unshift(:defaults).push(:overlay) scopes.each do |scope| conf = send scope if conf.is_a? String @settings.read_yaml File.read(conf) if File.readable?(conf) elsif conf.is_a? Hash @settings.deep_merge! conf end end end |
#defaults ⇒ Object
12 13 14 |
# File 'lib/vayacondios/configuration.rb', line 12 def defaults Hash.new end |
#global ⇒ Object
16 17 18 |
# File 'lib/vayacondios/configuration.rb', line 16 def global File.join('/etc/vayacondios', base_filename) end |
#overlay(conf = nil) ⇒ Object
24 25 26 27 |
# File 'lib/vayacondios/configuration.rb', line 24 def (conf = nil) @overlay = conf unless conf.nil? @overlay end |
#project ⇒ Object
20 21 22 |
# File 'lib/vayacondios/configuration.rb', line 20 def project File.join(ENV['PWD'], 'config', base_filename) end |
#resolve! ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/vayacondios/configuration.rb', line 54 def resolve! unless resolved? apply_all @resolved_settings = @settings.to_hash.symbolize_keys @resolved = true end end |
#resolved? ⇒ Boolean
29 30 31 |
# File 'lib/vayacondios/configuration.rb', line 29 def resolved? !!@resolved end |
#resolved_settings ⇒ Object
33 34 35 36 |
# File 'lib/vayacondios/configuration.rb', line 33 def resolved_settings resolve! @resolved_settings.dup end |