Class: Validator
- Inherits:
-
Object
- Object
- Validator
- Defined in:
- lib/kafo/validator.rb
Instance Method Summary collapse
-
#[](value, *args) ⇒ Object
for puppet >= 3.
-
#include?(value) ⇒ Boolean
for puppet >= 3.
-
#initialize(params) ⇒ Validator
constructor
A new instance of Validator.
- #lookupvar(name, options = {}) ⇒ Object
- #method_missing(method, *args, &block) ⇒ Object
Constructor Details
#initialize(params) ⇒ Validator
Returns a new instance of Validator.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/kafo/validator.rb', line 4 def initialize(params) files = KafoConfigure.modules_dir + '/*/lib/puppet/parser/functions/validate_*.rb' Dir.glob(files).each do |file| require file end @params = params @logger = KafoConfigure.logger @cache ||= Hash.new do |hash, key| @logger.debug "Looked for #{key}" param = @params.select { |p| p.name == key.to_s }.first hash[key] = param.nil? ? nil : param.value end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/kafo/validator.rb', line 34 def method_missing(method, *args, &block) method.to_s =~ /^function_(.*)$/ super unless $1 super unless Puppet::Parser::Functions.function($1) # In odd circumstances, this might not end up defined by the previous # method, so we might as well be certain. if engine.respond_to? method @logger.debug "calling #{method.inspect} with #{args.inspect}" engine.send(method, *args) else raise Puppet::DevError, "Function #{$1} not defined despite being loaded!" end rescue Puppet::ParseError => e @logger.error e. return false end |
Instance Method Details
#[](value, *args) ⇒ Object
for puppet >= 3
30 31 32 |
# File 'lib/kafo/validator.rb', line 30 def [](value, *args) lookupvar(value) end |
#include?(value) ⇒ Boolean
for puppet >= 3
25 26 27 |
# File 'lib/kafo/validator.rb', line 25 def include?(value) true end |
#lookupvar(name, options = {}) ⇒ Object
20 21 22 |
# File 'lib/kafo/validator.rb', line 20 def lookupvar(name, = {}) @cache[name] end |