Class: PuppetParse::Configuration

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

Class Method Summary collapse

Instance Method Summary collapse

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 - The value to set the option to.

Returns nothing.

Signature

<option>=(value)


51
52
53
54
55
56
57
58
59
# File 'lib/puppet-parse/configuration.rb', line 51

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_check(check) ⇒ Object

Internal: Add helper methods for a new check to the PuppetParse::Configuration object.

check - The String name of the check.

Returns nothing.

Signature

<check>_enabled?
disable_<check>
enable_<check>


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/puppet-parse/configuration.rb', line 18

def self.add_check(check)
  # Public: Determine if the named check is enabled.
  #
  # Returns true if the check is enabled, otherwise return false.
  define_method("#{check}_enabled?") do
    settings["#{check}_disabled"] == true ? false : true
  end

  # Public: Disable the named check.
  #
  # Returns nothing.
  define_method("disable_#{check}") do
    settings["#{check}_disabled"] = true
  end

  # Public: Enable the named check.
  #
  # Returns nothing.
  define_method("enable_#{check}") do
    settings["#{check}_disabled"] = false
  end
end

.add_option(option) ⇒ Object

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

option - The String name of the option.

Returns nothing.

Signature

<option>
<option>=(value)


87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/puppet-parse/configuration.rb', line 87

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_check(check, &b) ⇒ Object

Internal: Register a new check.

check - The String name of the check b - The Block containing the logic of the check

Returns nothing.



111
112
113
114
# File 'lib/puppet-parse/configuration.rb', line 111

def add_check(check, &b)
  self.class.add_check(check)
  check_method[check] = b
end

#add_helper(name, &b) ⇒ Object

Internal: Register a new check helper method.

name - The String name of the method. b - The Block containing the logic of the helper.

Returns nothing.



122
123
124
# File 'lib/puppet-parse/configuration.rb', line 122

def add_helper(name, &b)
  helper_method[name] = b
end

#add_option(option) ⇒ Object

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

option - The String name of the option.

Returns nothing.

Signature

<option>
<option>=(value)


72
73
74
# File 'lib/puppet-parse/configuration.rb', line 72

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

#check_methodObject

Internal: Access the internal storage for check method blocks.

Returns a Hash containing all the check blocks.



136
137
138
# File 'lib/puppet-parse/configuration.rb', line 136

def check_method
  @check_method ||= {}
end

#checksObject

Public: Get a list of all the defined checks.

Returns an Array of String check names.



143
144
145
# File 'lib/puppet-parse/configuration.rb', line 143

def checks
  check_method.keys
end

#defaultsObject

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

Returns nothing.



165
166
167
# File 'lib/puppet-parse/configuration.rb', line 165

def defaults
  settings.clear
end

#helper_methodObject

Internal: Access the internal storage for helper method blocks.

Returns a Hash containing all the helper blocks.



150
151
152
# File 'lib/puppet-parse/configuration.rb', line 150

def helper_method
  @helper_method ||= {}
end

#helpersObject

Public: Get a list of all the helper methods.

Returns an Array of String method names.



157
158
159
# File 'lib/puppet-parse/configuration.rb', line 157

def helpers
  helper_method.keys
end

#settingsObject

Internal: Access the internal storage for settings.

Returns a Hash containing all the settings.



129
130
131
# File 'lib/puppet-parse/configuration.rb', line 129

def settings
  @settings ||= {}
end