diff --git a/lib/trailblazer/operation.rb b/lib/trailblazer/operation.rb index 2748a14..2635bca 100644 --- a/lib/trailblazer/operation.rb +++ b/lib/trailblazer/operation.rb @@ -50,8 +50,8 @@ class << self require "trailblazer/operation/public_call" # TODO: Remove in 3.0. extend PublicCall # ::call(params: .., current_user: ..) - require "trailblazer/operation/trace" - extend Trace # ::trace + require "trailblazer/operation/wtf" + extend Wtf # ::trace end end diff --git a/lib/trailblazer/operation/trace.rb b/lib/trailblazer/operation/trace.rb deleted file mode 100644 index 757b967..0000000 --- a/lib/trailblazer/operation/trace.rb +++ /dev/null @@ -1,67 +0,0 @@ -require "delegate" -require "trailblazer/developer" - -module Trailblazer - class Operation - module Trace - # @note The problem in this method is, we have redundancy with Operation::PublicCall - def self.call(operation, options) - # warn %{Trailblazer: `Operation.trace` is deprecated. Please use `Operation.wtf?`.} # DISCUSS: should this be deprecated? - ctx = PublicCall.options_for_public_call(options) # redundant with PublicCall::call. - - stack, signal, (ctx, _flow_options) = Developer::Trace.(operation, [ctx, {}]) - - result = Railway::Result(signal, ctx) # redundant with PublicCall::call. - - Result.new(result, stack) - end - - # `Operation::trace` is included for simple tracing of the flow. - # It simply forwards all arguments to `Trace.call`. - # - # @public - # - # Operation.trace(params, current_user: current_user).wtf - # TODO: remove in 0.11.0. - def trace(options) - Activity::Deprecate.warn Trace.find_caller_location_for_deprecated, %(Using `Operation.trace` is deprecated and will be removed in {trailblazer-operation-0.11.0}. - Please use `#{self}.wtf?` as documented here: https://trailblazer.to/2.1/docs/trailblazer#trailblazer-developer-wtf-) - - Trace.(self, options) - end - - def wtf?(options) - call_with_public_interface(options, {}, invoke_class: Developer::Wtf) - end - - # TODO: remove in 0.11.0. - def self.find_caller_location_for_deprecated - our_caller_locations = caller_locations.to_a - caller_location = our_caller_locations.reverse.find { |line| line.to_s =~ /operation\/trace/ } - - _caller_location = our_caller_locations[our_caller_locations.index(caller_location)+1] - end - - # Presentation of the traced stack via the returned result object. - # This object is wrapped around the original result in {Trace.call}. - class Result < ::SimpleDelegator - def initialize(result, stack) - super(result) - @stack = stack - end - - # TODO: remove in 0.11.0. - def wtf - Activity::Deprecate.warn Trace.find_caller_location_for_deprecated, %(Using `result.wtf?` is deprecated. Please use `#{@stack.to_a[0].task}.wtf?` and have a nice day.) - - Developer::Trace::Present.(@stack) - end - - # TODO: remove in 0.11.0. - def wtf? - puts wtf - end - end - end - end -end diff --git a/lib/trailblazer/operation/wtf.rb b/lib/trailblazer/operation/wtf.rb new file mode 100644 index 0000000..35f0340 --- /dev/null +++ b/lib/trailblazer/operation/wtf.rb @@ -0,0 +1,11 @@ +require "trailblazer/developer" + +module Trailblazer + class Operation + module Wtf + def wtf?(options) + call_with_public_interface(options, {}, invoke_class: Developer::Wtf) + end + end + end +end diff --git a/test/call_test.rb b/test/call_test.rb index 90162f2..9ae8334 100644 --- a/test/call_test.rb +++ b/test/call_test.rb @@ -65,11 +65,9 @@ def self.add_1(wrap_ctx, original_args) result.inspect(:seq).must_equal %{} # with tracing - result = operation.trace(seq: []) + result = operation.wtf?(seq: []) result.inspect(:seq).must_equal %{} - - result.wtf? end diff --git a/test/trace_test.rb b/test/trace_test.rb index 56d64c4..0ffe806 100644 --- a/test/trace_test.rb +++ b/test/trace_test.rb @@ -13,38 +13,13 @@ class Create < Trailblazer::Operation step ->(_options, params:, **) { params.any? }, id: "Create.task.params" end - it "deprecates {result.wtf?} and {Operation.trace}" do - output, warning = capture_io do - result = Create.trace({a_return: true, params: {}}) - result.wtf? - end - line_no = __LINE__ - 2 - - assert_equal warning, %([Trailblazer] #{File.realpath(__FILE__)}:#{line_no - 1} Using `Operation.trace` is deprecated and will be removed in {trailblazer-operation-0.11.0}. - Please use `TraceTest::Create.wtf?` as documented here: https://trailblazer.to/2.1/docs/trailblazer#trailblazer-developer-wtf- -[Trailblazer] #{File.realpath(__FILE__)}:#{line_no} Using `result.wtf?` is deprecated. Please use `TraceTest::Create.wtf?` and have a nice day. -) - assert_equal output, %(TraceTest::Create -|-- Start.default -|-- Create.task.a -|-- MyNested -| |-- Start.default -| |-- B.task.b -| |-- B.task.e -| `-- End.success -|-- Create.task.c -|-- Create.task.params -`-- End.failure -) - end - it "allows using low-level Operation::Trace" do - result = Trailblazer::Operation::Trace.( + stack, result = Trailblazer::Developer::Trace.( Create, { a_return: true, params: {} }, ) - output = result.wtf + output = Trailblazer::Developer::Trace::Present.(stack) assert_equal output.gsub(/0x\w+/, "").gsub(/@.+_test/, ""), %{TraceTest::Create |-- Start.default @@ -59,21 +34,6 @@ class Create < Trailblazer::Operation `-- End.failure} end - it "Operation::trace" do - result = Create.trace(params: {x: 1}, a_return: true) - assert_equal result.wtf.gsub(/0x\w+/, "").gsub(/@.+_test/, ""), %{TraceTest::Create -|-- Start.default -|-- Create.task.a -|-- MyNested -| |-- Start.default -| |-- B.task.b -| |-- B.task.e -| `-- End.success -|-- Create.task.c -|-- Create.task.params -`-- End.success} - end - it "Operation.wtf?" do result = nil output, = capture_io do