Class: Addressive::Graph::Builder
- Inherits:
-
Object
- Object
- Addressive::Graph::Builder
- Defined in:
- lib/addressive/graph.rb
Overview
A Builder is used to construct a network. It’s here so that a Addressive::Graph can have only read methods, while a Builder does the heavy lifting. This class should not be generated directly, it’s created for you by #build and #initialize.
Instance Method Summary collapse
-
#default(name, value) ⇒ Object
Sets a network-wide default.
-
#initialize(network) ⇒ Builder
constructor
A new instance of Builder.
-
#node(name) {|NodeBuilder| ... } ⇒ NodeBuilder
Creates or edits the node with the given name in the current network and yields and returns a NodeBuilder.
Constructor Details
#initialize(network) ⇒ Builder
Returns a new instance of Builder.
164 165 166 |
# File 'lib/addressive/graph.rb', line 164 def initialize(network) @network = network end |
Instance Method Details
#default(name, value) ⇒ Object
Note:
Only nodes created after this default has been set will receive this value.
Sets a network-wide default.
189 190 191 |
# File 'lib/addressive/graph.rb', line 189 def default(name,value) @network.spec_factory.defaults[name]=value end |
#node(name) {|NodeBuilder| ... } ⇒ NodeBuilder
Creates or edits the node with the given name in the current network and yields and returns a NodeBuilder. This NodeBuilder can then be use to actually describe the node.
173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/addressive/graph.rb', line 173 def node(name, &block) n = @network.node(name) if block if block.arity == 1 yield @network.node_builder_class.new(@network, n) else @network.node_builder_class.new(@network, n).instance_eval(&block) end end return @network.node_builder_class.new(@network, n) end |