Class: Core::Operation::Action

Inherits:
Object
  • Object
show all
Includes:
Inspect, State
Defined in:
lib/core/operation/action.rb

Overview

public

An operation action.

Direct Known Subclasses

Core::Operation::Actions::Block

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Action

Returns a new instance of Action.



41
42
43
44
# File 'lib/core/operation/action.rb', line 41

def initialize(name)
  @name = (name || :call).to_sym
  @reference = self.class.build_reference.to_sym
end

Instance Attribute Details

#nameObject (readonly)

public

The action name.



48
49
50
# File 'lib/core/operation/action.rb', line 48

def name
  @name
end

#referenceObject (readonly)

public

The action reference.



52
53
54
# File 'lib/core/operation/action.rb', line 52

def reference
  @reference
end

Class Method Details

.build(target = nil, *args, &block) ⇒ Object

public

Builds an action for a given target.

Raises:

  • (ArgumentError)


18
19
20
21
22
# File 'lib/core/operation/action.rb', line 18

def build(target = nil, *args, &block)
  raise ArgumentError, "actions must be defined with a block" unless block

  Actions::Block.new(target, &block)
end

.build_referenceObject



24
25
26
27
28
29
30
31
32
# File 'lib/core/operation/action.rb', line 24

def build_reference
  suffix = generate_random_suffix
  if __used_random_suffixes__.include?(suffix)
    build_reference
  else
    __used_random_suffixes__ << suffix
    "action_#{suffix}"
  end
end

.generate_random_suffixObject



34
35
36
# File 'lib/core/operation/action.rb', line 34

def generate_random_suffix
  SecureRandom.hex(8)
end

Instance Method Details

#finalize(context) ⇒ Object

public

Finalizes the action for the given context.



56
57
58
# File 'lib/core/operation/action.rb', line 56

def finalize(context)
  raise "not implemented"
end