Class: Kafo::PuppetConfigurer

Inherits:
Object
  • Object
show all
Defined in:
lib/kafo/puppet_configurer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_path, settings = {}) ⇒ PuppetConfigurer

Returns a new instance of PuppetConfigurer.



7
8
9
10
11
# File 'lib/kafo/puppet_configurer.rb', line 7

def initialize(config_path, settings = {})
  @config_path = config_path
  @settings = {'reports' => ''}.merge(settings)
  @logger = KafoConfigure.logger
end

Instance Attribute Details

#config_pathObject (readonly)

Returns the value of attribute config_path.



5
6
7
# File 'lib/kafo/puppet_configurer.rb', line 5

def config_path
  @config_path
end

#loggerObject (readonly)

Returns the value of attribute logger.



5
6
7
# File 'lib/kafo/puppet_configurer.rb', line 5

def logger
  @logger
end

Instance Method Details

#[](key) ⇒ Object



13
14
15
# File 'lib/kafo/puppet_configurer.rb', line 13

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

#[]=(key, value) ⇒ Object



17
18
19
# File 'lib/kafo/puppet_configurer.rb', line 17

def []=(key, value)
  @settings[key] = value
end

#write_configObject



21
22
23
24
25
26
27
28
29
# File 'lib/kafo/puppet_configurer.rb', line 21

def write_config
  @logger.debug("Writing Puppet config file at #{config_path}")
  File.open(config_path, 'w') do |file|
    file.puts '[main]'
    @settings.keys.sort.each do |key|
      file.puts "#{key} = #{@settings[key]}"
    end
  end
end