Class: Dynflow::Serializers::Abstract Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/dynflow/serializers/abstract.rb

Overview

This class is abstract.

Used to serialize and deserialize arguments for storage in a database. Used by DelayedPlan to store arguments which should be passed into the Action‘s #plan method when the plan is executed.

Direct Known Subclasses

Noop

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args, serialized_args = nil) ⇒ Abstract

Returns a new instance of Abstract.

Parameters:

  • args (Array)

    arguments to be serialized

  • serialized_args (nil, Array) (defaults to: nil)

    arguments in their serialized form



14
15
16
17
# File 'lib/dynflow/serializers/abstract.rb', line 14

def initialize(args, serialized_args = nil)
  @args = args
  @serialized_args = serialized_args
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



10
11
12
# File 'lib/dynflow/serializers/abstract.rb', line 10

def args
  @args
end

#serialized_argsObject (readonly)

Returns the value of attribute serialized_args.



10
11
12
# File 'lib/dynflow/serializers/abstract.rb', line 10

def serialized_args
  @serialized_args
end

Instance Method Details

#args!Array

Retrieves the arguments

Returns:

  • (Array)

    the arguments

Raises:

  • (RuntimeError)

    if the deserialized arguments are not available



23
24
25
26
# File 'lib/dynflow/serializers/abstract.rb', line 23

def args!
  raise "@args not set" if @args.nil?
  return @args
end

#deserialize(arg) ⇒ Object

Converts a serialized argument into its deserialized form

Parameters:

  • arg

    the argument to be deserialized

Raises:

  • (NotImplementedError)


65
66
67
# File 'lib/dynflow/serializers/abstract.rb', line 65

def deserialize(arg)
  raise NotImplementedError
end

#perform_deserialization!Array

Converts arguments into their deserialized form, iterates over serialized arguments, applying #deserialize to each of them

Returns:

  • (Array)

    the deserialized arguments

Raises:

  • (RuntimeError)

    if the serialized arguments are not available



51
52
53
# File 'lib/dynflow/serializers/abstract.rb', line 51

def perform_deserialization!
  @args = serialized_args!.map { |arg| deserialize arg }
end

#perform_serialization!Array

Converts arguments into their serialized form, iterates over deserialized arguments, applying #serialize to each of them

Returns:

  • (Array)

    the serialized arguments

Raises:

  • (RuntimeError)

    if the deserialized arguments are not available



42
43
44
# File 'lib/dynflow/serializers/abstract.rb', line 42

def perform_serialization!
  @serialized_args = args!.map { |arg| serialize arg }
end

#serialize(arg) ⇒ Object

Converts an argument into it serialized form

Parameters:

  • arg

    the argument to be serialized

Raises:

  • (NotImplementedError)


58
59
60
# File 'lib/dynflow/serializers/abstract.rb', line 58

def serialize(arg)
  raise NotImplementedError
end

#serialized_args!Array

Retrieves the arguments in the serialized form

Returns:

  • (Array)

    the serialized arguments

Raises:

  • (RuntimeError)

    if the serialized arguments are not available



32
33
34
35
# File 'lib/dynflow/serializers/abstract.rb', line 32

def serialized_args!
  raise "@serialized_args not set" if @serialized_args.nil?
  return @serialized_args
end