Module: Psychgus::Ext::YAMLTreeExt
- Defined in:
- lib/psychgus/ext/yaml_tree_ext.rb
Overview
Extensions to Psych::Visitors::YAMLTree.
Instance Method Summary collapse
-
#accept(target) ⇒ Object
Accepts a new Object to convert to YAML.
Instance Method Details
#accept(target) ⇒ Object
Accepts a new Object to convert to YAML.
This is roughly the same place where Psych checks if target responds to :encode_with.
-
Check if @emitter is a StyledTreeBuilder.
-
If #1 and
targetis a Blueberry, get the Styler(s) fromtargetand add them to @emitter. -
If #1 and @emitter.deref_aliases?, prevent
targetfrom becoming an alias. -
Call
superand store the result. -
If #2, remove the Styler(s) from @emitter.
-
Return the result of
super.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/psychgus/ext/yaml_tree_ext.rb', line 65 def accept(target) styler_count = 0 if @emitter.is_a?(StyledTreeBuilder) # Blueberry? if target.respond_to?(:psychgus_stylers) stylers = target.psychgus_stylers(@emitter.sniffer) stylers_old_len = @emitter.stylers.length @emitter.add_styler(*stylers) styler_count = @emitter.stylers.length - stylers_old_len end # Dereference aliases? @st.psychgus_unregister(target) if @emitter.deref_aliases? end result = super(target) # rubocop:disable Style/SuperArguments # Check styler_count because @emitter may not be a StyledTreeBuilder and target may not be a Blueberry @emitter.pop_styler(styler_count) if styler_count > 0 return result end |