Class: Treat::Workers::Formatters::Serializers::YAML

Inherits:
Object
  • Object
show all
Defined in:
lib/treat/workers/formatters/serializers/yaml.rb

Overview

Serialization of entities to YAML format.

Class Method Summary collapse

Class Method Details

.serialize(entity, options = {}) ⇒ Object

Serialize an entity in YAML format.

Options:

  • (String) :file => a file to write to.



13
14
15
16
17
18
19
20
21
22
# File 'lib/treat/workers/formatters/serializers/yaml.rb', line 13

def self.serialize(entity, options = {})
  yaml = ::YAML.dump(entity)
  options[:file] ||= (entity.id.to_s + '.yml')
  if options[:file]
    File.open(options[:file], 'w') do |f| 
      f.write(yaml)
    end
  end
  options[:file]
end