Class: I28s::Cli::YamlDumper
- Inherits:
-
Object
- Object
- I28s::Cli::YamlDumper
- Defined in:
- lib/i28s/cli/yaml_dumper.rb
Class Method Summary collapse
-
.dump(object) ⇒ Object
We want to dump strings that contain newlines as literal scalars for readability Inspired by github.com/ruby/psych/issues/322#issuecomment-328408276.
Class Method Details
.dump(object) ⇒ Object
We want to dump strings that contain newlines as literal scalars for readability Inspired by github.com/ruby/psych/issues/322#issuecomment-328408276
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/i28s/cli/yaml_dumper.rb', line 8 def self.dump(object) str = YAML.dump(object) ast = Psych.parse_stream(str) ast.grep(Psych::Nodes::Scalar).each do |node| node.style = Psych::Nodes::Scalar::LITERAL if node.value.include?("\n") end ast.yaml(nil, {line_width: -1}) end |