Module: SnippetCli::YamlParamRenderer
- Defined in:
- lib/snippet_cli/yaml_param_renderer.rb
Overview
Renders variable param key/value pairs as YAML lines with proper indentation.
Class Method Summary collapse
Class Method Details
.lines(key, val, indent) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/snippet_cli/yaml_param_renderer.rb', line 8 def self.lines(key, val, indent) case val when Hash then hash_lines(key, val, indent) when Array then ["#{indent}#{key}:", *val.map { |item| "#{indent} - #{YamlScalar.quote(item.to_s)}" }] when true, false then ["#{indent}#{key}: #{val}"] else scalar_lines(key, val.to_s, indent) end end |
.scalar_lines(key, str, indent) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/snippet_cli/yaml_param_renderer.rb', line 24 def self.scalar_lines(key, str, indent) if str.include?("\n") indented = str.lines.map { |line| "#{indent} #{line.chomp}" }.join("\n") ["#{indent}#{key}: |", indented] else ["#{indent}#{key}: #{YamlScalar.quote(str)}"] end end |