Class: ConfigToolkit::YAMLWriter::Visitor
- Inherits:
-
HashArrayVisitor
- Object
- HashArrayVisitor
- ConfigToolkit::YAMLWriter::Visitor
- Defined in:
- lib/configtoolkit/yamlwriter.rb
Overview
This class is used for converting the elements of the structure passed to write to standard YAML types. See the comments for HashArrayVisitor for details on how this visitor works.
As this visitor visits the nodes of a structure, it builds up a parallel structure that is the same as the original except that all elements are of standard YAML types.
Defined Under Namespace
Classes: StackFrame
Instance Attribute Summary collapse
-
#config_hash ⇒ Object
readonly
The structure currently being built.
Instance Method Summary collapse
- #enter_array(array) ⇒ Object
- #enter_hash(hash) ⇒ Object
-
#initialize ⇒ Visitor
constructor
A new instance of Visitor.
- #visit_array_element(value, index, is_container) ⇒ Object
- #visit_hash_element(key, value, index, is_container) ⇒ Object
Methods inherited from HashArrayVisitor
#leave_array, #leave_hash, #stack_empty?, #stack_top, #visit
Constructor Details
#initialize ⇒ Visitor
Returns a new instance of Visitor.
83 84 85 86 87 88 |
# File 'lib/configtoolkit/yamlwriter.rb', line 83 def initialize @config_hash = {} @next_container = @config_hash super() end |
Instance Attribute Details
#config_hash ⇒ Object (readonly)
The structure currently being built.
75 76 77 |
# File 'lib/configtoolkit/yamlwriter.rb', line 75 def config_hash @config_hash end |
Instance Method Details
#enter_array(array) ⇒ Object
133 134 135 |
# File 'lib/configtoolkit/yamlwriter.rb', line 133 def enter_array(array) return StackFrame.new(@next_container) end |
#enter_hash(hash) ⇒ Object
119 120 121 |
# File 'lib/configtoolkit/yamlwriter.rb', line 119 def enter_hash(hash) return StackFrame.new(@next_container) end |
#visit_array_element(value, index, is_container) ⇒ Object
137 138 139 140 141 142 143 144 145 |
# File 'lib/configtoolkit/yamlwriter.rb', line 137 def visit_array_element(value, index, is_container) converted_value = convert_value(value) if(is_container) @next_container = converted_value end stack_top().container.push(converted_value) end |
#visit_hash_element(key, value, index, is_container) ⇒ Object
123 124 125 126 127 128 129 130 131 |
# File 'lib/configtoolkit/yamlwriter.rb', line 123 def visit_hash_element(key, value, index, is_container) converted_value = convert_value(value) if(is_container) @next_container = converted_value end stack_top().container[key] = converted_value end |