Module: Textus::Workflow::DSL::StepBuilder
- Included in:
- Definition
- Defined in:
- lib/textus/workflow/dsl/step_builder.rb
Instance Method Summary collapse
- #build_check(name, naming: nil, scope: nil, &block) ⇒ Object
- #build_parallel(steps) ⇒ Object
- #build_step(name, callable = nil, timeout: nil, &block) ⇒ Object
Instance Method Details
#build_check(name, naming: nil, scope: nil, &block) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/textus/workflow/dsl/step_builder.rb', line 23 def build_check(name, naming: nil, scope: nil, &block) merge = lambda { |data, new_issues| existing = Array(data&.dig("content", "issues")) all = existing + new_issues { "content" => { "ok" => all.empty?, "issues" => all, "count" => all.size } } } if naming raise ArgumentError.new("check :#{name} requires a scope: for naming checks") unless scope lambda { |data, ctx| entries = ctx.container.manifest.resolver.enumerate.select do |row| match_pattern?(scope, row[:key].to_s) end new_issues = check_naming( entries, pattern: naming, code: "check.#{name}", fix: "rename to match #{naming.inspect}" ) merge.call(data, new_issues) } elsif block ->(data, ctx) { merge.call(data, block.call(ctx) || []) } else raise ArgumentError.new("check :#{name} requires naming: or a block") end end |
#build_parallel(steps) ⇒ Object
50 51 52 |
# File 'lib/textus/workflow/dsl/step_builder.rb', line 50 def build_parallel(steps) Parallel.new(steps: steps) end |
#build_step(name, callable = nil, timeout: nil, &block) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/textus/workflow/dsl/step_builder.rb', line 5 def build_step(name, callable = nil, timeout: nil, &block) if callable.is_a?(Hash) raise ArgumentError.new( "step :#{name} no longer accepts options hash; pass timeout: keyword instead", ) end resolved = if callable.respond_to?(:call) callable elsif block block else raise ArgumentError.new("step :#{name} requires a block or a callable (got neither)") end Step.new(name: name, callable: resolved, timeout: timeout) end |