Class: Brandish::Parser::Node
- Inherits:
-
Object
- Object
- Brandish::Parser::Node
- Defined in:
- lib/brandish/parser/node.rb,
lib/brandish/parser/node/pair.rb,
lib/brandish/parser/node/root.rb,
lib/brandish/parser/node/text.rb,
lib/brandish/parser/node/block.rb,
lib/brandish/parser/node/string.rb,
lib/brandish/parser/node/command.rb
Overview
A parser node. This is the base for all parser nodes.b All parser nodes are frozen, and so cannot be mutated; all mutations need to be set up as a new node, that is then returned.
Defined Under Namespace
Classes: Block, Command, Pair, Root, String, Text
Instance Attribute Summary collapse
-
#location ⇒ Location
readonly
The location of the node.
Instance Method Summary collapse
-
#initialize(location:) ⇒ Node
constructor
Initialize the node with the given location.
-
#inspect ⇒ ::String
Pretty inspect.
-
#prevent_update ⇒ Node
Prevents all calls to #update.
-
#update(attributes) ⇒ Node
"Updates" the node with the given attributes.
- #update_prevented? ⇒ Boolean
Constructor Details
#initialize(location:) ⇒ Node
Initialize the node with the given location. This should be overwritten by a decending node, but all decending nodes should include a location.
28 29 30 |
# File 'lib/brandish/parser/node.rb', line 28 def initialize(location:) @location = location end |
Instance Attribute Details
#location ⇒ Location (readonly)
The location of the node.
20 21 22 |
# File 'lib/brandish/parser/node.rb', line 20 def location @location end |
Instance Method Details
#inspect ⇒ ::String
Pretty inspect.
35 36 37 |
# File 'lib/brandish/parser/node.rb', line 35 def inspect "#<#{self.class} location=#{@location}>" end |
#prevent_update ⇒ Node
Prevents all calls to #update. This is used on nodes that should never be updated. This is a stop-gap measure for incorrectly configured projects. This, in line with all other methods, creates a duplicate node.
65 66 67 68 69 |
# File 'lib/brandish/parser/node.rb', line 65 def prevent_update node = dup node.singleton_class.send(:undef_method, :update) node end |
#update(attributes) ⇒ Node
"Updates" the node with the given attributes. All of the key-value pairs in the attributes are updated on the node by sending an update to the node.
55 56 57 |
# File 'lib/brandish/parser/node.rb', line 55 def update(attributes) attributes.inject(self) { |a, (n, v)| a.update_attribute(n, v) } end |
#update_prevented? ⇒ Boolean
71 72 73 |
# File 'lib/brandish/parser/node.rb', line 71 def update_prevented? !respond_to?(:update) end |