Class: StyledYAML::TreeBuilder
- Inherits:
-
Psych::TreeBuilder
- Object
- Psych::TreeBuilder
- StyledYAML::TreeBuilder
- Defined in:
- lib/locomotive/wagon/tools/styled_yaml.rb
Overview
Custom tree builder class to recognize scalars tagged with ‘yaml_style`
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#initialize(*args) ⇒ TreeBuilder
constructor
A new instance of TreeBuilder.
- #scalar(value, anchor, tag, plain, quoted, style) ⇒ Object
- #style_any?(style) ⇒ Boolean
- #style_literal?(style) ⇒ Boolean
Constructor Details
#initialize(*args) ⇒ TreeBuilder
Returns a new instance of TreeBuilder.
56 57 58 59 |
# File 'lib/locomotive/wagon/tools/styled_yaml.rb', line 56 def initialize(*args) super @next_sequence_or_mapping_style = nil end |
Instance Attribute Details
#next_sequence_or_mapping_style(default_style) ⇒ Object
61 62 63 64 65 |
# File 'lib/locomotive/wagon/tools/styled_yaml.rb', line 61 def next_sequence_or_mapping_style default_style style = @next_sequence_or_mapping_style || default_style @next_sequence_or_mapping_style = nil style end |
Instance Method Details
#scalar(value, anchor, tag, plain, quoted, style) ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/locomotive/wagon/tools/styled_yaml.rb', line 67 def scalar value, anchor, tag, plain, quoted, style if style_any?(style) and value.respond_to?(:yaml_style) and style = value.yaml_style if style_literal? style plain = false quoted = true end end super end |
#style_any?(style) ⇒ Boolean
77 |
# File 'lib/locomotive/wagon/tools/styled_yaml.rb', line 77 def style_any?(style) Psych::Nodes::Scalar::ANY == style end |
#style_literal?(style) ⇒ Boolean
79 |
# File 'lib/locomotive/wagon/tools/styled_yaml.rb', line 79 def style_literal?(style) Psych::Nodes::Scalar::LITERAL == style end |