Class: Core::Pipeline::Action

Inherits:
Object
  • Object
show all
Includes:
Inspect, State
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, curry: false) ⇒ Action

Returns a new instance of Action.



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

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

Instance Attribute Details

#afterObject (readonly)

[public] The name of the action this action should be called after.



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

def after
  @after
end

#beforeObject (readonly)

[public] The name of the action this action should be called before.



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

def before
  @before
end

#contextObject (readonly)

[public] The context this action should be called in.



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

def context
  @context
end

#nameObject (readonly)

[public] The action name.



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

def name
  @name
end

Class Method Details

.build(target = nil, *args, before: nil, after: nil, context: nil, curry: false, &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, curry: false, &block)
  if block
    Actions::Block.new(target, before: before, after: after, context: context, curry: curry, &block)
  else
    build_target(target, *args, before: before, after: after, context: context, curry: curry)
  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

#curried?Boolean

[public] Returns true if the action should be curried.

Returns:

  • (Boolean)


84
85
86
# File 'lib/core/pipeline/action.rb', line 84

def curried?
  @curry == true
end

#finalize(context) ⇒ Object

[public] Finalizes the action for the given context.



90
91
92
# File 'lib/core/pipeline/action.rb', line 90

def finalize(context)
  raise "not implemented"
end