Class: YamlExporter::LiteralString

Inherits:
String
  • Object
show all
Defined in:
lib/yaml_exporter/exporter.rb

Overview

Marker subclass: a String that must be emitted as a YAML literal block scalar (|). Attribute nodes wrap the values of text columns in this so the Exporter's visitor can render them as block scalars regardless of length, while string/varchar columns stay inline.

Trailing whitespace on a line (a space/tab before a newline) makes libyaml's emitter refuse block style and silently fall back to a double-quoted inline scalar — which is exactly what breaks the "text columns are always block scalars" promise. Such whitespace is virtually always an accidental typo, so we strip it per line on construction. This also normalizes CR (\r\n/\r), which trips the same fallback.

Class Method Summary collapse

Class Method Details

.new(value) ⇒ Object



16
17
18
# File 'lib/yaml_exporter/exporter.rb', line 16

def self.new(value)
  super(normalize(value.to_s))
end

.normalize(value) ⇒ Object



20
21
22
# File 'lib/yaml_exporter/exporter.rb', line 20

def self.normalize(value)
  value.split("\n", -1).map(&:rstrip).join("\n")
end