Class: ConfigToolkit::PrettyPrintWriter
- Defined in:
- lib/configtoolkit/prettyprintwriter.rb
Overview
This class implements the Writer interface for pretty printing configuration classes to specified streams. This is used by BaseConfig#to_s.
Defined Under Namespace
Classes: Visitor
Instance Method Summary collapse
-
#initialize(stream) ⇒ PrettyPrintWriter
constructor
Description: This constructs a PrettyPrintWriter instance for
stream
, wherestream
either is a file name (a String) or an IO object. -
#require_symbol_parameter_names? ⇒ Boolean
Returns: Returns
true
, since the PrettyPrintWriter requires Symbol parameter names in the hash passed to write. -
#write(config_hash, containing_object_name) ⇒ Object
Description: This method pretty prints
config_hash
to the underlying stream.
Methods inherited from Writer
#create_containing_object_hash
Constructor Details
#initialize(stream) ⇒ PrettyPrintWriter
Description:
This constructs a PrettyPrintWriter instance for stream
, where stream
either is a file name (a String) or an IO object.
Parameters:
- stream
-
A file name (String) or an IO object. If
stream
is a file name, then the PrettyPrintWriter will open the associated file.
26 27 28 29 30 31 32 |
# File 'lib/configtoolkit/prettyprintwriter.rb', line 26 def initialize(stream) if(stream.class == String) @stream = File.open(stream, "w") else @stream = stream end end |
Instance Method Details
#require_symbol_parameter_names? ⇒ Boolean
Returns:
Returns true
, since the PrettyPrintWriter requires Symbol parameter names in the hash passed to write.
140 141 142 |
# File 'lib/configtoolkit/prettyprintwriter.rb', line 140 def require_symbol_parameter_names? return true end |
#write(config_hash, containing_object_name) ⇒ Object
Description:
This method pretty prints config_hash
to the underlying stream.
Parameters:
- config_hash
-
The configuration hash to write
- containing_object_name
-
The configuration’s containing object name
154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/configtoolkit/prettyprintwriter.rb', line 154 def write(config_hash, containing_object_name) if(!containing_object_name.empty?()) @stream << "#{containing_object_name}: " end Visitor.new(@stream).visit(config_hash) @stream << "\n" @stream.flush() end |