Class: Synthra::Export::YamlData
- Defined in:
- lib/synthra/export/yaml_data.rb
Overview
Exports generated data as YAML
Instance Method Summary collapse
Constructor Details
This class inherits a constructor from Synthra::Export::Base
Instance Method Details
#export ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/synthra/export/yaml_data.rb', line 15 def export count = [:count] || 10 seed = [:seed] mode = [:mode] || :random records = if count == 1 schema.generate(seed: seed, mode: mode, registry: registry) # single record else schema.generate_many(count, seed: seed, mode: mode, registry: registry) end output = wrap_output(records) # Add header comment lines = [] lines << "# Generated from Synthra schema: #{schema.name}" lines << "# Version: #{schema.version}" if schema.version lines << "# Records: #{count}" lines << "# Generated at: #{Time.now.iso8601}" lines << "" lines << YAML.dump(output) lines.join("\n") end |
#wrap_output(records) ⇒ Object (private)
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/synthra/export/yaml_data.rb', line 42 def wrap_output(records) # :nocov: if [:wrap] == false records # :nocov: elsif [:root_key] { [:root_key] => records } else records end end |