Class: ParamBuilder
- Inherits:
-
Object
- Object
- ParamBuilder
- Defined in:
- lib/kafo/param_builder.rb
Constant Summary collapse
- ATTRIBUTE_RE =
/^(type):(.*)/
Instance Method Summary collapse
- #build(name, default, docs) ⇒ Object
- #build_params ⇒ Object
-
#initialize(mod, data) ⇒ ParamBuilder
constructor
A new instance of ParamBuilder.
- #validate ⇒ Object
Constructor Details
#initialize(mod, data) ⇒ ParamBuilder
Returns a new instance of ParamBuilder.
5 6 7 8 |
# File 'lib/kafo/param_builder.rb', line 5 def initialize(mod, data) @data = data @module = mod end |
Instance Method Details
#build(name, default, docs) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/kafo/param_builder.rb', line 30 def build(name, default, docs) param = get_type(docs).new(@module, name) param.default = default param.doc = get_documentation(docs) param end |
#build_params ⇒ Object
24 25 26 27 28 |
# File 'lib/kafo/param_builder.rb', line 24 def build_params @data['parameters'].keys.map do |param_name| build(param_name, @data['parameters'][param_name], @data['docs'][param_name]) end end |
#validate ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/kafo/param_builder.rb', line 10 def validate parameters = @data['parameters'].keys.sort docs = @data['docs'].keys.sort if parameters == docs return true else undocumented = parameters - docs raise ConfigurationException, "undocumented parameters in #{@module.name}: #{undocumented.join(', ')}" unless undocumented.empty? deleted = docs - parameters raise ConfigurationException, "documentation mentioned unknown parameters in #{@module.name}: #{deleted.join(', ')}" unless deleted.empty? raise ConfigurationException, "unknown error in configuration in #{@module.name}" end end |