Class: Textus::Workflow::DSL::Definition
- Inherits:
-
Object
- Object
- Textus::Workflow::DSL::Definition
- 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
-
#handled_events ⇒ Object
readonly
Returns the value of attribute handled_events.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#notify_keys ⇒ Object
readonly
Returns the value of attribute notify_keys.
-
#on_patterns ⇒ Object
readonly
Returns the value of attribute on_patterns.
-
#publish_block ⇒ Object
readonly
Returns the value of attribute publish_block.
-
#publish_targets ⇒ Object
readonly
Returns the value of attribute publish_targets.
-
#save_to ⇒ Object
readonly
Returns the value of attribute save_to.
-
#steps ⇒ Object
readonly
Returns the value of attribute steps.
-
#workflow_type ⇒ Object
readonly
Returns the value of attribute workflow_type.
Class Method Summary collapse
Instance Method Summary collapse
- #check(name, naming: nil, scope: nil) ⇒ Object
-
#every(cadence = :__no_arg__) ⇒ Object
(also: #ttl)
── Lifecycle ──.
-
#handles(*event_types) ⇒ Object
── Event handling (internal) ──.
-
#initialize(name) ⇒ Definition
constructor
A new instance of Definition.
-
#match?(key) ⇒ Boolean
── Matching (internal) ──.
- #max_attempts(n = nil) ⇒ Object
- #multi_match? ⇒ Boolean
- #notify(key) ⇒ Object
-
#on(*patterns) ⇒ Object
── Trigger ──.
- #on_expire(action = :__no_arg__) ⇒ Object
- #parallel ⇒ Object
-
#priority(n = nil) ⇒ Object
── Ordering ──.
-
#publish(to: nil, template: nil, tree: nil, inject_boot: nil, &block) ⇒ Object
── Output ──.
- #save(to:) ⇒ Object
-
#step(name, callable = nil, timeout: nil) ⇒ Object
── Steps ──.
- #type ⇒ Object
Methods included from Lifecycle
#expire_action, #max_attempts_value, #priority_value, #ttl_value
Methods included from PatternMatcher
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_events ⇒ Object (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 |
#name ⇒ Object (readonly)
Returns the value of attribute name.
13 14 15 |
# File 'lib/textus/workflow/dsl.rb', line 13 def name @name end |
#notify_keys ⇒ Object (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_patterns ⇒ Object (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_block ⇒ Object (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_targets ⇒ Object (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_to ⇒ Object (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 |
#steps ⇒ Object (readonly)
Returns the value of attribute steps.
13 14 15 |
# File 'lib/textus/workflow/dsl.rb', line 13 def steps @steps end |
#workflow_type ⇒ Object (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_registered ⇒ Object
26 27 28 |
# File 'lib/textus/workflow/dsl.rb', line 26 def self.clear_registered @definitions = [] end |
.definitions ⇒ Object
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) ──
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
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 |
#parallel ⇒ Object
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 |
#type ⇒ Object
49 50 51 |
# File 'lib/textus/workflow/dsl.rb', line 49 def type @workflow_type end |