Class: PuppetGhostbuster::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet-ghostbuster/configuration.rb

Overview

Public: A singleton class to store the running configuration of puppet-ghostbuster.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



6
7
8
# File 'lib/puppet-ghostbuster/configuration.rb', line 6

def initialize
  Puppet.initialize_settings
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object

Public: Catch situations where options are being set for the first time and create the necessary methods to get & set the option in the future.

args - An Array of values to set the option to. method - The String name of the option. block - Unused.

Returns nothing.

Signature

<option>=(value)


22
23
24
25
26
27
28
29
30
# File 'lib/puppet-ghostbuster/configuration.rb', line 22

def method_missing(method, *args, &block)
  if method.to_s =~ /^(\w+)=$/
    option = $1
    add_option(option.to_s) if settings[option].nil?
    settings[option] = args[0]
  else
    nil
  end
end

Class Method Details

.add_option(option) ⇒ Object

Public: Add an option to the PuppetGhostbuster::Configuration object from outside the class.

option - The String name of the option.

Returns nothing.

Signature

<option>
<option>=(value)


58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/puppet-ghostbuster/configuration.rb', line 58

def self.add_option(option)
  # Public: Set the value of the named option.
  #
  # value - The value to set the option to.
  #
  # Returns nothing.
  define_method("#{option}=") do |value|
    settings[option] = value
  end

  # Public: Get the value of the named option.
  #
  # Returns the value of the option.
  define_method(option) do
    settings[option]
  end
end

Instance Method Details

#add_option(option) ⇒ Object

Internal: Add options to the PuppetGhostbuster::Configuration object from inside the class.

option - The String name of the option.

Returns nothing.

Signature

<option>
<option>=(value)


43
44
45
# File 'lib/puppet-ghostbuster/configuration.rb', line 43

def add_option(option)
  self.class.add_option(option)
end

#defaultsObject

Public: Clear the PuppetGhostbuster::Configuration storage and set some sane default values.

Returns nothing.



87
88
89
90
91
92
93
94
# File 'lib/puppet-ghostbuster/configuration.rb', line 87

def defaults
  settings.clear
  self.loglevel = Logger::INFO
  self.puppetdbserverurl = "https://#{Puppet[:server]}:8081"
  self.hostprivkey = Puppet[:hostprivkey]
  self.hostcert    = Puppet[:hostcert]
  self.localcacert = Puppet[:localcacert]
end

#settingsObject

Internal: Access the internal storage for settings.

Returns a Hash containing all the settings.



79
80
81
# File 'lib/puppet-ghostbuster/configuration.rb', line 79

def settings
  @settings ||= {}
end