Class: NagiosConfig::Builder
- Inherits:
-
Object
- Object
- NagiosConfig::Builder
show all
- Defined in:
- lib/nagios_config/builder.rb
Overview
Usage:
conf = NagiosConfig::Builder.new
conf.foo = "bar"
conf.define("test") do |test|
test.a = "b"
test.a.("foo")
end
puts conf
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(root = NagiosConfig::Config.new) ⇒ Builder
Returns a new instance of Builder.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
53
54
55
56
57
58
59
60
61
|
# File 'lib/nagios_config/builder.rb', line 53
def method_missing(name, *args)
if name.to_s =~ /=$/ && args.length == 1
self[name.to_s.chomp("=")] = args.first
elsif args.empty?
self[name]
else
super
end
end
|
Instance Attribute Details
Returns the value of attribute root.
14
15
16
|
# File 'lib/nagios_config/builder.rb', line 14
def root
@root
end
|
Instance Method Details
20
21
22
23
24
25
|
# File 'lib/nagios_config/builder.rb', line 20
def [](name)
var = get_variable_named(name)
if var
extend(var.val.value, var)
end
end
|
#[]=(name, value) ⇒ Object
27
28
29
30
|
# File 'lib/nagios_config/builder.rb', line 27
def []=(name, value)
set_variable_named(name, value)
value
end
|
#define(type) {|self.class.new(define)| ... } ⇒ Object