Class: Stepped::Definition

Inherits:
Object
  • Object
show all
Defined in:
app/models/stepped/definition.rb

Constant Summary collapse

AFTER_CALLBACKS =
%i[
  cancelled
  timed_out
  succeeded
  failed
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(actor_class:, action_name:, outbound: false, timeout: nil, job: nil, block: nil) ⇒ Definition

Returns a new instance of Definition.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/models/stepped/definition.rb', line 15

def initialize(actor_class:, action_name:, outbound: false, timeout: nil, job: nil, block: nil)
  @actor_class = actor_class
  @action_name = action_name.to_s
  @outbound = outbound || job.present?
  @timeout = timeout
  @job = job
  @after_callbacks = []
  @steps = []
  @block = block

  instance_exec &block if block

  if @steps.empty?
    @steps.append generate_step
  end
end

Instance Attribute Details

#action_nameObject (readonly)

Returns the value of attribute action_name.



2
3
4
# File 'app/models/stepped/definition.rb', line 2

def action_name
  @action_name
end

#actor_classObject (readonly)

Returns the value of attribute actor_class.



2
3
4
# File 'app/models/stepped/definition.rb', line 2

def actor_class
  @actor_class
end

#after_callbacksObject (readonly)

Returns the value of attribute after_callbacks.



2
3
4
# File 'app/models/stepped/definition.rb', line 2

def after_callbacks
  @after_callbacks
end

#before_blockObject (readonly)

Returns the value of attribute before_block.



2
3
4
# File 'app/models/stepped/definition.rb', line 2

def before_block
  @before_block
end

#blockObject (readonly)

Returns the value of attribute block.



2
3
4
# File 'app/models/stepped/definition.rb', line 2

def block
  @block
end

#checksum_blockObject (readonly)

Returns the value of attribute checksum_block.



2
3
4
# File 'app/models/stepped/definition.rb', line 2

def checksum_block
  @checksum_block
end

#checksum_key_blockObject (readonly)

Returns the value of attribute checksum_key_block.



2
3
4
# File 'app/models/stepped/definition.rb', line 2

def checksum_key_block
  @checksum_key_block
end

#concurrency_key_blockObject (readonly)

Returns the value of attribute concurrency_key_block.



2
3
4
# File 'app/models/stepped/definition.rb', line 2

def concurrency_key_block
  @concurrency_key_block
end

#jobObject (readonly)

Returns the value of attribute job.



2
3
4
# File 'app/models/stepped/definition.rb', line 2

def job
  @job
end

#outboundObject (readonly)

Returns the value of attribute outbound.



2
3
4
# File 'app/models/stepped/definition.rb', line 2

def outbound
  @outbound
end

#stepsObject (readonly)

Returns the value of attribute steps.



2
3
4
# File 'app/models/stepped/definition.rb', line 2

def steps
  @steps
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



2
3
4
# File 'app/models/stepped/definition.rb', line 2

def timeout
  @timeout
end

Instance Method Details

#after(*statuses, &block) ⇒ Object



66
67
68
69
70
71
72
73
74
75
# File 'app/models/stepped/definition.rb', line 66

def after(*statuses, &block)
  statuses = [ :all ] if statuses.empty?
  statuses.each do |status|
    status = status.to_sym
    unless status == :all || AFTER_CALLBACKS.include?(status)
      raise ArgumentError, "'#{status}' must be one of #{AFTER_CALLBACKS}"
    end
    after_callbacks << { name: status, block: }
  end
end

#before(&block) ⇒ Object



36
37
38
# File 'app/models/stepped/definition.rb', line 36

def before(&block)
  @before_block = block
end

#checksum(method = nil, &block) ⇒ Object



44
45
46
# File 'app/models/stepped/definition.rb', line 44

def checksum(method = nil, &block)
  @checksum_block = procify method, &block
end

#checksum_key(method = nil, &block) ⇒ Object



48
49
50
# File 'app/models/stepped/definition.rb', line 48

def checksum_key(method = nil, &block)
  @checksum_key_block = procify method, &block
end

#concurrency_key(method = nil, &block) ⇒ Object



40
41
42
# File 'app/models/stepped/definition.rb', line 40

def concurrency_key(method = nil, &block)
  @concurrency_key_block = procify method, &block
end

#duplicate_as(actor_class) ⇒ Object



32
33
34
# File 'app/models/stepped/definition.rb', line 32

def duplicate_as(actor_class)
  self.class.new(actor_class:, action_name:, outbound:, timeout:, job:, block:)
end

#prepend_step(&block) ⇒ Object



56
57
58
# File 'app/models/stepped/definition.rb', line 56

def prepend_step(&block)
  @steps.prepend block
end

#step(&block) ⇒ Object



52
53
54
# File 'app/models/stepped/definition.rb', line 52

def step(&block)
  @steps.append block
end