Class: Vayacondios::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/vayacondios/configuration.rb

Direct Known Subclasses

Server::Configuration

Instance Attribute Summary collapse

Instance Method Summary collapse

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_filenameObject

Returns the value of attribute base_filename.



4
5
6
# File 'lib/vayacondios/configuration.rb', line 4

def base_filename
  @base_filename
end

#load_orderObject

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_allObject



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

#defaultsObject



12
13
14
# File 'lib/vayacondios/configuration.rb', line 12

def defaults
  Hash.new
end

#globalObject



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 overlay(conf = nil)
  @overlay = conf unless conf.nil?
  @overlay
end

#projectObject



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

Returns:

  • (Boolean)


29
30
31
# File 'lib/vayacondios/configuration.rb', line 29

def resolved?
  !!@resolved
end

#resolved_settingsObject



33
34
35
36
# File 'lib/vayacondios/configuration.rb', line 33

def resolved_settings
  resolve!
  @resolved_settings.dup
end