Class: Core::Pipeline::Action

Inherits:
Object
  • Object
show all
Includes:
Is::Inspectable, Is::Stateful
Defined in:
lib/core/pipeline/action.rb

Overview

public

A pipeline action.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, before: nil, after: nil, context: nil) ⇒ Action

Returns a new instance of Action.



58
59
60
61
62
63
# File 'lib/core/pipeline/action.rb', line 58

def initialize(name, before: nil, after: nil, context: nil)
  @name = (name || self.class.build_name).to_sym
  @before = before
  @after = after
  @context = context
end

Instance Attribute Details

#afterObject (readonly)

public

The name of the action this action should be called after.



75
76
77
# File 'lib/core/pipeline/action.rb', line 75

def after
  @after
end

#beforeObject (readonly)

public

The name of the action this action should be called before.



71
72
73
# File 'lib/core/pipeline/action.rb', line 71

def before
  @before
end

#nameObject (readonly)

public

The action name.



67
68
69
# File 'lib/core/pipeline/action.rb', line 67

def name
  @name
end

Class Method Details

.build(target = nil, *args, before: nil, after: nil, context: nil, &block) ⇒ Object

public

Builds an action for a given target.



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

def build(target = nil, *args, before: nil, after: nil, context: nil, &block)
  if block
    Actions::Block.new(target, before: before, after: after, context: context, &block)
  else
    build_target(target, *args, before: before, after: after, context: context)
  end
end

.build_nameObject



41
42
43
44
45
46
47
48
49
# File 'lib/core/pipeline/action.rb', line 41

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

.generate_random_suffixObject



51
52
53
# File 'lib/core/pipeline/action.rb', line 51

def generate_random_suffix
  SecureRandom.hex(8)
end

Instance Method Details

#finalize(context) ⇒ Object

public

Finalizes the action for the given context.



79
80
81
# File 'lib/core/pipeline/action.rb', line 79

def finalize(context)
  raise "not implemented"
end