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
174 175 176 177 178 |
# File 'lib/tree_haver/backends/psych.rb', line 174 def initialize(stream, source) @inner_tree = stream @source = source @lines = source.lines end |
Instance Attribute Details
#inner_tree ⇒ ::Psych::Nodes::Stream (readonly)
165 166 167 |
# File 'lib/tree_haver/backends/psych.rb', line 165 def inner_tree @inner_tree end |
#source ⇒ String (readonly)
168 169 170 |
# File 'lib/tree_haver/backends/psych.rb', line 168 def source @source end |
Instance Method Details
#comments ⇒ Array
Get comments from the document
Psych doesn’t preserve comments in the AST by default.
211 212 213 |
# File 'lib/tree_haver/backends/psych.rb', line 211 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.
195 196 197 |
# File 'lib/tree_haver/backends/psych.rb', line 195 def errors [] end |
#inspect ⇒ String
216 217 218 |
# File 'lib/tree_haver/backends/psych.rb', line 216 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.
185 186 187 |
# File 'lib/tree_haver/backends/psych.rb', line 185 def root_node Node.new(@inner_tree, @source, @lines) end |
#warnings ⇒ Array
Get parse warnings
202 203 204 |
# File 'lib/tree_haver/backends/psych.rb', line 202 def warnings [] end |