Class: Kafo::Validator
- Inherits:
-
Object
- Object
- Kafo::Validator
- Defined in:
- lib/kafo/validator.rb
Class Method Summary collapse
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.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/kafo/validator.rb', line 11 def initialize(params) self.class.prepare_functions validate_files = KafoConfigure.modules_dir + '/*/lib/puppet/parser/functions/validate_*.rb' is_function_files = KafoConfigure.modules_dir + '/*/lib/puppet/parser/functions/is_*.rb' definitions = Dir.glob(validate_files) + Dir.glob(is_function_files) definitions.each do |file| require File.(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
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/kafo/validator.rb', line 45 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 |
Class Method Details
.prepare_functions ⇒ Object
5 6 7 8 9 |
# File 'lib/kafo/validator.rb', line 5 def self.prepare_functions return true if @reset || !Puppet::Parser::Functions.respond_to?(:reset) Puppet::Parser::Functions.reset @reset = true end |
Instance Method Details
#[](value, *args) ⇒ Object
for puppet >= 3
41 42 43 |
# File 'lib/kafo/validator.rb', line 41 def [](value, *args) lookupvar(value) end |
#include?(value) ⇒ Boolean
for puppet >= 3
36 37 38 |
# File 'lib/kafo/validator.rb', line 36 def include?(value) true end |
#lookupvar(name, options = {}) ⇒ Object
31 32 33 |
# File 'lib/kafo/validator.rb', line 31 def lookupvar(name, = {}) @cache[name] end |