Class: PuppetLint::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet-lint/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



17
18
19
20
21
22
23
24
25
# File 'lib/puppet-lint/configuration.rb', line 17

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



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/puppet-lint/configuration.rb', line 3

def self.add_check(check)
  define_method("#{check}_enabled?") do
    settings["#{check}_disabled"] == true ? false : true
  end

  define_method("disable_#{check}") do
    settings["#{check}_disabled"] = true
  end

  define_method("enable_#{check}") do
    settings["#{check}_disabled"] = false
  end
end

.add_option(option) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/puppet-lint/configuration.rb', line 31

def self.add_option(option)
  define_method("#{option}=") do |value|
    settings[option] = value
  end

  define_method(option) do
    settings[option]
  end
end

Instance Method Details

#add_check(check) ⇒ Object



41
42
43
# File 'lib/puppet-lint/configuration.rb', line 41

def add_check(check)
  self.class.add_check(check)
end

#add_option(option) ⇒ Object



27
28
29
# File 'lib/puppet-lint/configuration.rb', line 27

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

#checksObject



49
50
51
52
53
54
55
# File 'lib/puppet-lint/configuration.rb', line 49

def checks
  self.public_methods.select { |method|
    method =~ /^.+_enabled\?$/
  }.map { |method|
    method[0..-10]
  }
end

#settingsObject



45
46
47
# File 'lib/puppet-lint/configuration.rb', line 45

def settings
  @settings ||= {}
end