Class: AWS::Flow::YAMLDataConverter

Inherits:
Object
  • Object
show all
Defined in:
lib/aws/decider/data_converter.rb

Overview

Converts an object to YAML. Exceptions are handled differently because YAML doesn’t propagate backtraces properly, and they are very handy for debugging.

Instance Method Summary collapse

Instance Method Details

#dump(object) ⇒ Object

Serializes a ruby object into a YAML string.

Parameters:

  • object

    The object that needs to be serialized into a string.



27
28
29
30
31
32
# File 'lib/aws/decider/data_converter.rb', line 27

def dump(object)
  if object.is_a? Exception
    return YAML.dump_stream(object, object.backtrace)
  end
  object.to_yaml
end

#load(source) ⇒ Object

Deserializes a YAML string into a ruby object.

Parameters:

  • source

    The source YAML string that needs to be deserialized into a ruby object.



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/aws/decider/data_converter.rb', line 39

def load(source)
  return nil if source.nil?
  output = YAML.load source
  if output.is_a? Exception
    documents = YAML.load_stream(source)
    if YAML::ENGINE.yamler == 'syck'
      documents = documents.documents
    end
    backtrace = documents.find {|x| ! x.is_a? Exception}
    output.set_backtrace(backtrace.to_a)
  end
  output
end