Class: Loom::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/loom/config.rb

Defined Under Namespace

Classes: FileManager

Constant Summary collapse

CONFIG_VARS =
{
  :loom_search_paths => ['/etc/loom', File.join(ENV['HOME'], '.loom'), './.loom'],
  :loom_files => ['site.loom'],

  :inventory_all_hosts => false,
  :inventory_hosts => [],
  :inventory_groups => [],

  :log_level => :warn, # [debug, info, warn, error, fatal, or Integer]
  :log_device => :stderr, # [stderr, stdout, file descriptor, or file name]
  :log_colorize => true,

  :run_failure_strategy => :exclude_host, # [exclude_host, fail_fast, cowboy]
  :run_verbose => false,

  :sshkit_execution_strategy => :sequence, # [sequence, parallel, groups]
  :sshkit_log_level => :warn,
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**config_map) ⇒ Config

Returns a new instance of Config.



31
32
33
34
35
36
37
38
39
# File 'lib/loom/config.rb', line 31

def initialize(**config_map)
  config_map.each do |k,v|
    # allows attr_reader methods from CONFIG_VAR to work
    instance_variable_set :"@#{k}", v
  end

  @config_map = config_map
  @file_manager = FileManager.new self
end

Class Method Details

.configure(config = nil) {|config_struct| ... } ⇒ Object

Yields:

  • (config_struct)


55
56
57
58
59
60
61
62
63
# File 'lib/loom/config.rb', line 55

def configure(config=nil, &block)
  # do NOT call Loom.log inside this block, the logger may not be
  # configured, triggering an infinite recursion

  map = config ? config.config_map : CONFIG_VARS.dup
  config_struct = OpenStruct.new **map
  yield config_struct if block_given?
  Config.new config_struct.to_h
end

Instance Method Details

#[](key) ⇒ Object



41
42
43
# File 'lib/loom/config.rb', line 41

def [](key)
  @config_map[key]
end

#filesObject



50
51
52
# File 'lib/loom/config.rb', line 50

def files
  @file_manager
end

#to_yamlObject Also known as: dump



45
46
47
# File 'lib/loom/config.rb', line 45

def to_yaml
  @config_map.to_yaml
end