Class: OBIX::Builder
- Inherits:
-
Object
- Object
- OBIX::Builder
- Defined in:
- lib/obix/builder.rb
Instance Attribute Summary collapse
-
#objects ⇒ Object
readonly
Returns the value of attribute objects.
Instance Method Summary collapse
-
#initialize(parent = nil, &block) ⇒ Builder
constructor
Initialize a new builder.
-
#method_missing(method, attributes = {}, &block) ⇒ Object
Respond to methods matching OBIX tags.
- #object ⇒ Object
Constructor Details
#initialize(parent = nil, &block) ⇒ Builder
Initialize a new builder.
parent - An Objects::Object instance or derivative thereof describing the parent
of the object that will be built.
10 11 12 13 14 15 |
# File 'lib/obix/builder.rb', line 10 def initialize parent = nil, &block @parent = parent @objects = [] instance_eval &block end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, attributes = {}, &block) ⇒ Object
Respond to methods matching OBIX tags.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/obix/builder.rb', line 22 def method_missing method, attributes = {}, &block klass = Objects.find method object = klass.new &block attributes.each do |key, value| object.send "#{key}=", value end object.parent = @parent if @parent @objects.push object else if @objects.empty? @objects.push object else raise ArgumentError, "Object already has a root" end end end |
Instance Attribute Details
#objects ⇒ Object (readonly)
Returns the value of attribute objects.
4 5 6 |
# File 'lib/obix/builder.rb', line 4 def objects @objects end |
Instance Method Details
#object ⇒ Object
17 18 19 |
# File 'lib/obix/builder.rb', line 17 def object objects.first end |