Skip to content

Commit

Permalink
feat: Add 'left' delegator to Strategy class
Browse files Browse the repository at this point in the history
  • Loading branch information
seuros committed Dec 2, 2024
1 parent e04338c commit 3f51bee
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion lib/trailblazer/macro/strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Macro
class Strategy # We want to look like a real {Linear::Strategy}.
class << self
extend Forwardable
def_delegators :block_activity, :step, :pass, :fail, :Subprocess # TODO: add all DSL::Helper
def_delegators :block_activity, :step, :pass, :fail, :left, :Subprocess # TODO: add all DSL::Helper
end

# This makes {Wrap} look like {block_activity}.
Expand Down
2 changes: 1 addition & 1 deletion test/docs/autogenerated/operation_each_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# step Macro::Each(:report_templates, key: :report_template) {
# step Subprocess(ReportTemplate::Update), input: :input_report_template
# fail :set_report_template_errors
# left :set_report_template_errors
# }

# def report_templates(ctx, **) ctx["result.contract.default"].report_templates
Expand Down
2 changes: 1 addition & 1 deletion test/docs/each_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# step Macro::Each(:report_templates, key: :report_template) {
# step Subprocess(ReportTemplate::Update), input: :input_report_template
# fail :set_report_template_errors
# left :set_report_template_errors
# }

# def report_templates(ctx, **) ctx["result.contract.default"].report_templates
Expand Down
14 changes: 7 additions & 7 deletions test/docs/rescue_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ class NestedInsanity < Trailblazer::Operation
step ->(options, **) { options["b"] = true }
pass ->(options, **) { raise A if options["raise-a"] }
step ->(options, **) { options["c"] = true }
fail ->(options, **) { options["inner-err"] = true }
left ->(options, **) { options["inner-err"] = true }
}
step ->(options, **) { options["e"] = true }, id: "nested/e"
fail ->(options, **) { options["outer-err"] = true }, id: "nested/failure"
left ->(options, **) { options["outer-err"] = true }, id: "nested/failure"
end

it { assert_match /\[>Rescue\/.{1,3},>nested/, Trailblazer::Developer.railway(NestedInsanity) } # FIXME: better introspect tests for all id-generating macros.
Expand Down Expand Up @@ -54,7 +54,7 @@ class Song::Activity::Create < Trailblazer::Activity::Railway
step :rehash
}
step :notify
fail :log_error
left :log_error
#~methods
include T.def_steps(:create_model, :upload, :notify, :log_error)
include Rehash
Expand Down Expand Up @@ -91,7 +91,7 @@ class Song::Activity::Create < Trailblazer::Activity::Railway
step :rehash
}
step :notify
fail :log_error
left :log_error
#~methods
include T.def_steps(:create_model, :upload, :notify, :log_error)
include Rehash
Expand Down Expand Up @@ -125,7 +125,7 @@ class Memo::Create < Trailblazer::Operation
step :rehash
}
step :notify
fail :log_error
left :log_error
include T.def_steps(:find_model, :update, :notify, :log_error)
include Rehash
end
Expand All @@ -148,7 +148,7 @@ class Memo::Create < Trailblazer::Operation
step :rehash
}
step :notify
fail :log_error
left :log_error
#~methods
include T.def_steps(:find_model, :update, :notify, :log_error)
include Rehash
Expand Down Expand Up @@ -180,7 +180,7 @@ class Memo::Create < Trailblazer::Operation
step :find_model
step Rescue(&rescue_block), fail_fast: true
step :notify
fail :log_error
left :log_error
#~methods
include T.def_steps(:find_model, :update, :notify, :log_error, :rehash)
end
Expand Down
28 changes: 14 additions & 14 deletions test/docs/wrap_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Upload < Trailblazer::Activity::FastTrack
step :transfer # this might even break!
}
step :notify
fail :log_error
left :log_error
#~meths
include T.def_steps(:model, :update, :transfer, :notify, :log_error)
#~meths end
Expand Down Expand Up @@ -63,7 +63,7 @@ class Upload < Trailblazer::Activity::FastTrack
Output(:timeout) => Track(:fail_fast) # any wiring is possible here.
#:out end
step :notify
fail :log_error
left :log_error
#~meths
include T.def_steps(:model, :update, :transfer, :notify, :log_error)
#~meths end
Expand Down Expand Up @@ -109,7 +109,7 @@ class Upload < Trailblazer::Activity::FastTrack
step :transfer # might raise an exception.
}
step :notify
fail :log_error
left :log_error
#~meths
include T.def_steps(:model, :update, :transfer, :notify, :log_error)
def transfer(ctx, seq:, transfer: true, **)
Expand Down Expand Up @@ -157,7 +157,7 @@ class Memo::Create < Trailblazer::Operation
step :rehash
}
step :notify
fail :log_error
left :log_error
#~methods
include T.def_steps(:model, :update, :notify, :log_error)
include Rehash
Expand Down Expand Up @@ -196,7 +196,7 @@ def self.call((ctx), *, &block)
step :rehash
}, fail_fast: true
step :notify
fail :log_error
left :log_error

#~methods
include T.def_steps(:model, :update, :notify, :log_error)
Expand Down Expand Up @@ -233,7 +233,7 @@ class Memo::Create < Trailblazer::Operation
step :rehash
}, fast_track: true
step :notify
fail :log_error
left :log_error
#~methods
include T.def_steps(:model, :update, :notify, :log_error)
include Rehash
Expand Down Expand Up @@ -274,7 +274,7 @@ class Memo::Create < Trailblazer::Operation
Output(:success) => End(:transaction_worked),
Output(MyTransaction::MyFailSignal, :failure) => End(:transaction_failed)
step :notify
fail :log_error
left :log_error
#~methods
include T.def_steps(:model, :update, :notify, :log_error)
include Rehash
Expand Down Expand Up @@ -319,7 +319,7 @@ def self.call((ctx), *, &block)
step :rehash
}
step :notify
fail :log_error
left :log_error

#~methods
include T.def_steps(:model, :update, :notify, :log_error)
Expand Down Expand Up @@ -354,7 +354,7 @@ def self.call((ctx), *, &block)
step :rehash
}
step :notify
fail :log_error
left :log_error

#~methods
include T.def_steps(:model, :update, :notify, :log_error)
Expand Down Expand Up @@ -393,7 +393,7 @@ def self.call((ctx), *, &block)
step :rehash
}
step :notify
fail :log_error
left :log_error

#~methods
include T.def_steps(:model, :update, :notify, :log_error)
Expand Down Expand Up @@ -432,7 +432,7 @@ def self.call((ctx), *, &block)
step :rehash
}
step :notify
fail :log_error
left :log_error

#~methods
include T.def_steps(:model, :update, :notify, :log_error)
Expand Down Expand Up @@ -480,7 +480,7 @@ class Memo::Create < Trailblazer::Operation
step :rehash
}
step :notify
fail :log_error
left :log_error
#~methods
include T.def_steps(:model, :update, :notify, :log_error)
include Rehash
Expand Down Expand Up @@ -521,7 +521,7 @@ class Memo::Create < Trailblazer::Operation
step :update
}, fast_track: true # because Wrap can return pass_fast! now
step :notify
fail :log_error
left :log_error
#~methods
include T.def_steps(:model, :update, :notify, :log_error)
#~methods end
Expand Down Expand Up @@ -554,7 +554,7 @@ class Upload < Trailblazer::Activity::FastTrack
},
Output(:timeout__) => Track(:fail_fast)
step :upload
fail :log_error
left :log_error
#~methods
include T.def_steps(:model, :send_request, :upload, :log_error)
#~methods end
Expand Down

0 comments on commit 3f51bee

Please sign in to comment.