Class: Bumbleworks::TreeBuilder
- Inherits:
-
Object
- Object
- Bumbleworks::TreeBuilder
- Defined in:
- lib/bumbleworks/tree_builder.rb
Defined Under Namespace
Classes: InvalidTree
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#tree ⇒ Object
readonly
Returns the value of attribute tree.
Class Method Summary collapse
Instance Method Summary collapse
- #build! ⇒ Object
-
#initialize(options) ⇒ TreeBuilder
constructor
A new instance of TreeBuilder.
Constructor Details
#initialize(options) ⇒ TreeBuilder
Returns a new instance of TreeBuilder.
10 11 12 13 14 15 16 17 |
# File 'lib/bumbleworks/tree_builder.rb', line 10 def initialize() @forced_name = [:name] @definition = [:definition] @tree = [:tree] unless !!@definition ^ !!@tree raise ArgumentError, "Must specify either definition or tree (not both)" end end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/bumbleworks/tree_builder.rb', line 8 def name @name end |
#tree ⇒ Object (readonly)
Returns the value of attribute tree.
8 9 10 |
# File 'lib/bumbleworks/tree_builder.rb', line 8 def tree @tree end |
Class Method Details
.from_definition(*args, &block) ⇒ Object
34 35 36 37 |
# File 'lib/bumbleworks/tree_builder.rb', line 34 def from_definition(*args, &block) tree = ::Ruote.define *args, &block builder = new(:tree => tree) end |
Instance Method Details
#build! ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/bumbleworks/tree_builder.rb', line 19 def build! initialize_tree_from_definition! unless @tree if @name = name_from_tree @forced_name ||= name raise InvalidTree, "Name does not match name in definition" if @forced_name != @name @tree[1].delete(@tree[1].keys.first) end @name = @forced_name add_name_to_tree! @tree rescue ::Ruote::Reader::Error => e raise InvalidTree, e. end |