Class: Textus::Workflow::DSL::Definition

Inherits:
Object
  • Object
show all
Includes:
Lifecycle, PatternMatcher, StepBuilder
Defined in:
lib/textus/workflow/dsl.rb

Constant Summary

Constants included from Lifecycle

Lifecycle::VALID_EXPIRE_ACTIONS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Lifecycle

#expire_action, #max_attempts_value, #priority_value, #ttl_value

Methods included from PatternMatcher

#match_pattern?

Methods included from StepBuilder

#build_check, #build_parallel, #build_step

Constructor Details

#initialize(name) ⇒ Definition

Returns a new instance of Definition.



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/textus/workflow/dsl.rb', line 30

def initialize(name)
  @name                = name
  @steps               = []
  @on_patterns         = []
  @save_to             = nil
  @notify_keys         = []
  @publish_block       = nil
  @publish_targets     = []
  @priority            = 0
  @handled_events      = []
  @max_attempts        = 3
  @workflow_type       = name
end

Instance Attribute Details

#handled_eventsObject (readonly)

Returns the value of attribute handled_events.



13
14
15
# File 'lib/textus/workflow/dsl.rb', line 13

def handled_events
  @handled_events
end

#nameObject (readonly)

Returns the value of attribute name.



13
14
15
# File 'lib/textus/workflow/dsl.rb', line 13

def name
  @name
end

#notify_keysObject (readonly)

Returns the value of attribute notify_keys.



13
14
15
# File 'lib/textus/workflow/dsl.rb', line 13

def notify_keys
  @notify_keys
end

#on_patternsObject (readonly)

Returns the value of attribute on_patterns.



13
14
15
# File 'lib/textus/workflow/dsl.rb', line 13

def on_patterns
  @on_patterns
end

#publish_blockObject (readonly)

Returns the value of attribute publish_block.



13
14
15
# File 'lib/textus/workflow/dsl.rb', line 13

def publish_block
  @publish_block
end

#publish_targetsObject (readonly)

Returns the value of attribute publish_targets.



13
14
15
# File 'lib/textus/workflow/dsl.rb', line 13

def publish_targets
  @publish_targets
end

#save_toObject (readonly)

Returns the value of attribute save_to.



13
14
15
# File 'lib/textus/workflow/dsl.rb', line 13

def save_to
  @save_to
end

#stepsObject (readonly)

Returns the value of attribute steps.



13
14
15
# File 'lib/textus/workflow/dsl.rb', line 13

def steps
  @steps
end

#workflow_typeObject (readonly)

Returns the value of attribute workflow_type.



13
14
15
# File 'lib/textus/workflow/dsl.rb', line 13

def workflow_type
  @workflow_type
end

Class Method Details

.clear_registeredObject



26
27
28
# File 'lib/textus/workflow/dsl.rb', line 26

def self.clear_registered
  @definitions = []
end

.definitionsObject



22
23
24
# File 'lib/textus/workflow/dsl.rb', line 22

def self.definitions
  @definitions || []
end

.register(defn) ⇒ Object



17
18
19
20
# File 'lib/textus/workflow/dsl.rb', line 17

def self.register(defn)
  @definitions ||= []
  @definitions << defn
end

Instance Method Details

#check(name, naming: nil, scope: nil) ⇒ Object



69
70
71
72
# File 'lib/textus/workflow/dsl.rb', line 69

def check(name, naming: nil, scope: nil, &)
  callable = build_check(name, naming:, scope:, &)
  @steps << Step.new(name: :"check_#{name}", callable: callable, timeout: nil)
end

#every(cadence = :__no_arg__) ⇒ Object Also known as: ttl

── Lifecycle ──



109
110
111
112
113
# File 'lib/textus/workflow/dsl.rb', line 109

def every(cadence = :__no_arg__)
  return @ttl if cadence == :__no_arg__

  @ttl = ttl_value(cadence)
end

#handles(*event_types) ⇒ Object

── Event handling (internal) ──



45
46
47
# File 'lib/textus/workflow/dsl.rb', line 45

def handles(*event_types)
  @handled_events.concat(event_types.map(&:to_s).freeze)
end

#match?(key) ⇒ Boolean

── Matching (internal) ──

Returns:

  • (Boolean)


122
123
124
125
126
# File 'lib/textus/workflow/dsl.rb', line 122

def match?(key)
  return false unless @on_patterns&.any?

  @on_patterns.any? { |p| match_pattern?(p, key) }
end

#max_attempts(n = nil) ⇒ Object



53
54
55
56
57
# File 'lib/textus/workflow/dsl.rb', line 53

def max_attempts(n = nil)
  return @max_attempts if n.nil?

  @max_attempts = max_attempts_value(n)
end

#multi_match?Boolean

Returns:

  • (Boolean)


128
129
130
# File 'lib/textus/workflow/dsl.rb', line 128

def multi_match?
  @on_patterns&.any? { |p| p.end_with?("**") }
end

#notify(key) ⇒ Object



97
98
99
# File 'lib/textus/workflow/dsl.rb', line 97

def notify(key)
  @notify_keys << key
end

#on(*patterns) ⇒ Object

── Trigger ──



60
61
62
# File 'lib/textus/workflow/dsl.rb', line 60

def on(*patterns)
  @on_patterns = patterns
end

#on_expire(action = :__no_arg__) ⇒ Object



117
118
119
# File 'lib/textus/workflow/dsl.rb', line 117

def on_expire(action = :__no_arg__)
  @on_expire = expire_action(action)
end

#parallelObject



74
75
76
77
78
79
80
# File 'lib/textus/workflow/dsl.rb', line 74

def parallel(&)
  saved = @steps
  @steps = []
  instance_eval(&)
  parallel_steps = @steps.dup
  @steps = saved << build_parallel(parallel_steps)
end

#priority(n = nil) ⇒ Object

── Ordering ──



102
103
104
105
106
# File 'lib/textus/workflow/dsl.rb', line 102

def priority(n = nil)
  return @priority if n.nil?

  @priority = priority_value(n)
end

#publish(to: nil, template: nil, tree: nil, inject_boot: nil, &block) ⇒ Object

── Output ──



83
84
85
86
87
88
89
90
91
# File 'lib/textus/workflow/dsl.rb', line 83

def publish(to: nil, template: nil, tree: nil, inject_boot: nil, &block)
  if block
    @publish_block = block
  elsif to || tree
    @publish_targets << PublishTarget.new(to: to, template: template, tree: tree, inject_boot: inject_boot)
  else
    raise ArgumentError.new("publish requires to: (file), tree:, or a block; use save to: for store keys")
  end
end

#save(to:) ⇒ Object



93
94
95
# File 'lib/textus/workflow/dsl.rb', line 93

def save(to:)
  @save_to = to
end

#step(name, callable = nil, timeout: nil) ⇒ Object

── Steps ──



65
66
67
# File 'lib/textus/workflow/dsl.rb', line 65

def step(name, callable = nil, timeout: nil, &)
  @steps << build_step(name, callable, timeout:, &)
end

#typeObject



49
50
51
# File 'lib/textus/workflow/dsl.rb', line 49

def type
  @workflow_type
end