class ComfyConf::Checker
Attributes
data[R]
definition[R]
given_prefix[R]
Public Class Methods
new(definition, given_prefix, data)
click to toggle source
# File lib/comfy_conf/checker.rb, line 3 def initialize(definition, given_prefix, data) @definition, @given_prefix, @data = definition, given_prefix, data end
Public Instance Methods
check()
click to toggle source
# File lib/comfy_conf/checker.rb, line 8 def check definition.props.each {|p| check_prop(p) } definition.configs.each {|c| check_config(c) } end
prefix()
click to toggle source
# File lib/comfy_conf/checker.rb, line 13 def prefix given_prefix end
Private Instance Methods
check_config(config)
click to toggle source
# File lib/comfy_conf/checker.rb, line 20 def check_config(config) if config.required and not valid_section(config) raise MissingSection, "Expected configuration #{prefix} to contain "\ "section #{config.name} but it does not" \ end end
check_prop(prop)
click to toggle source
# File lib/comfy_conf/checker.rb, line 31 def check_prop(prop) ensure_present(prop) if prop.required ensure_type(prop) if data[prop] end
ensure_present(prop)
click to toggle source
# File lib/comfy_conf/checker.rb, line 44 def ensure_present(prop) if not data[prop.name] raise MissingOption, "Configuration property #{prefixed_name(prop)} is required!" end end
ensure_type(prop)
click to toggle source
# File lib/comfy_conf/checker.rb, line 36 def ensure_type(prop) if not data[prop.name].kind_of?(prop.type) raise InvalidOption, "Expect type #{prop.type} for "\ "configuration property #{prefixed_name(prop)}, "\ "got #{data[prop.name].class}" end end
prefixed_name(prop)
click to toggle source
# File lib/comfy_conf/checker.rb, line 51 def prefixed_name(prop) if prefix "#{prefix}[#{prop.name}]" else prop.name end end
valid_section(config)
click to toggle source
# File lib/comfy_conf/checker.rb, line 27 def valid_section(config) data[config.name] and data[config.name].kind_of?(Hash) end