Class: TreeHaver::Backends::Psych::Tree
- Inherits:
-
Object
- Object
- TreeHaver::Backends::Psych::Tree
- Defined in:
- lib/tree_haver/backends/psych.rb
Overview
Psych tree wrapper
Wraps a Psych::Nodes::Stream to provide TreeHaver-compatible tree interface.
Instance Attribute Summary collapse
-
#inner_tree ⇒ ::Psych::Nodes::Stream
readonly
The underlying Psych stream.
-
#source ⇒ String
readonly
The original source.
Instance Method Summary collapse
-
#comments ⇒ Array
Get comments from the document.
-
#errors ⇒ Array
Get parse errors.
-
#initialize(stream, source) ⇒ Tree
constructor
Create a new tree wrapper.
-
#inspect ⇒ String
Human-readable representation.
-
#root_node ⇒ Node
Get the root node.
-
#warnings ⇒ Array
Get parse warnings.
Constructor Details
#initialize(stream, source) ⇒ Tree
Create a new tree wrapper
198 199 200 201 202 |
# File 'lib/tree_haver/backends/psych.rb', line 198 def initialize(stream, source) @inner_tree = stream @source = source @lines = source.lines end |
Instance Attribute Details
#inner_tree ⇒ ::Psych::Nodes::Stream (readonly)
Returns The underlying Psych stream.
189 190 191 |
# File 'lib/tree_haver/backends/psych.rb', line 189 def inner_tree @inner_tree end |
#source ⇒ String (readonly)
Returns The original source.
192 193 194 |
# File 'lib/tree_haver/backends/psych.rb', line 192 def source @source end |
Instance Method Details
#comments ⇒ Array
Get comments from the document
Psych doesn’t preserve comments in the AST by default.
235 236 237 |
# File 'lib/tree_haver/backends/psych.rb', line 235 def comments [] end |
#errors ⇒ Array
Get parse errors
Psych raises exceptions on parse errors rather than recording them, so this is always empty if we got a tree.
219 220 221 |
# File 'lib/tree_haver/backends/psych.rb', line 219 def errors [] end |
#inspect ⇒ String
Returns human-readable representation.
240 241 242 |
# File 'lib/tree_haver/backends/psych.rb', line 240 def inspect "#<TreeHaver::Backends::Psych::Tree documents=#{@inner_tree.children&.size || 0}>" end |
#root_node ⇒ Node
Get the root node
For YAML, the stream is the root. We wrap it as a Node.
209 210 211 |
# File 'lib/tree_haver/backends/psych.rb', line 209 def root_node Node.new(@inner_tree, @source, @lines) end |
#warnings ⇒ Array
Get parse warnings
226 227 228 |
# File 'lib/tree_haver/backends/psych.rb', line 226 def warnings [] end |