Class: RightScale::CommandSerializer

Inherits:
Object
  • Object
show all
Defined in:
lib/right_agent/command/command_serializer.rb

Constant Summary collapse

SEPARATOR =

String appended to serialized data to delimit between commands

"\n#GO\n"

Class Method Summary collapse

Class Method Details

.dump(command) ⇒ Object

Serialize given command so it can be sent to command listener

Parameters

command(Object)

Command to serialize

Return

data(String)

Corresponding serialized data



38
39
40
41
# File 'lib/right_agent/command/command_serializer.rb', line 38

def self.dump(command)
  data = YAML::dump(command)
  data += SEPARATOR
end

.load(data) ⇒ Object

Deserialize command that was previously serialized with dump

Parameters

data(String)

String containing serialized data

Return

command(Object)

Deserialized command

Raise

(RightScale::Exceptions::IO): If serialized data is incorrect



53
54
55
56
57
58
59
60
61
# File 'lib/right_agent/command/command_serializer.rb', line 53

def self.load(data)
  command = YAML::load(data)
  raise RightScale::Exceptions::IO, "Invalid serialized command:\n#{data}" unless command
  command
rescue RightScale::Exceptions::IO
  raise
rescue Exception => e
  raise RightScale::Exceptions::IO, "Invalid serialized command: #{e.message}\n#{data}"
end