Class: Pvectl::Formatters::Yaml
- Defined in:
- lib/pvectl/formatters/yaml.rb
Overview
Formats data as YAML output.
Collections are rendered as YAML arrays. Single resources are rendered as YAML mappings. Empty collections return āā []nā. Nil values are rendered as YAML null (~).
Instance Method Summary collapse
-
#format(data, presenter, color_enabled: true, describe: false, **context) ⇒ String
Formats data as YAML output.
Instance Method Details
#format(data, presenter, color_enabled: true, describe: false, **context) ⇒ String
Formats data as YAML output.
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/pvectl/formatters/yaml.rb', line 36 def format(data, presenter, color_enabled: true, describe: false, **context) if describe && !collection?(data) # Use to_description for describe mode presenter.to_description(data).to_yaml elsif collection?(data) hashes = data.map { |model| presenter.to_hash(model) } hashes.to_yaml else presenter.to_hash(data).to_yaml end end |