Class: StyledYAML::TreeBuilder
- Inherits:
-
Psych::TreeBuilder
- Object
- Psych::TreeBuilder
- StyledYAML::TreeBuilder
- Defined in:
- lib/locomotive/mounter/utils/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.
59 60 61 62 |
# File 'lib/locomotive/mounter/utils/yaml.rb', line 59 def initialize(*args) super @next_sequence_or_mapping_style = nil end |
Instance Attribute Details
#next_sequence_or_mapping_style(default_style) ⇒ Object
64 65 66 67 68 |
# File 'lib/locomotive/mounter/utils/yaml.rb', line 64 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
70 71 72 73 74 75 76 77 78 |
# File 'lib/locomotive/mounter/utils/yaml.rb', line 70 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
80 |
# File 'lib/locomotive/mounter/utils/yaml.rb', line 80 def style_any?(style) Psych::Nodes::Scalar::ANY == style end |
#style_literal?(style) ⇒ Boolean
82 |
# File 'lib/locomotive/mounter/utils/yaml.rb', line 82 def style_literal?(style) Psych::Nodes::Scalar::LITERAL == style end |