Class: Protopack::StyledYAML::TreeBuilder
- Inherits:
-
Psych::TreeBuilder
- Object
- Psych::TreeBuilder
- Protopack::StyledYAML::TreeBuilder
- Defined in:
- lib/protopack/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.
58 59 60 61 |
# File 'lib/protopack/styled_yaml.rb', line 58 def initialize(*args) super @next_sequence_or_mapping_style = nil end |
Instance Attribute Details
#next_sequence_or_mapping_style(default_style) ⇒ Object
63 64 65 66 67 |
# File 'lib/protopack/styled_yaml.rb', line 63 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
69 70 71 72 73 74 75 76 77 |
# File 'lib/protopack/styled_yaml.rb', line 69 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
79 |
# File 'lib/protopack/styled_yaml.rb', line 79 def style_any?(style) Psych::Nodes::Scalar::ANY == style end |
#style_literal?(style) ⇒ Boolean
81 |
# File 'lib/protopack/styled_yaml.rb', line 81 def style_literal?(style) Psych::Nodes::Scalar::LITERAL == style end |