dry-rb / dry-transaction

Business transaction DSL
http://dry-rb.org/gems/dry-transaction
MIT License
468 stars 55 forks source link

<try> method applied to Transaction class add steps to Transaction #91

Closed vanitu closed 6 years ago

vanitu commented 6 years ago

Applying method on class with transaction resulted in additions of steps/operations

Example

class SomeTransaction
  include Dry::Transaction

  step :some

  def some(input)
    Right(input)
  end
end
2.4.2 :035 > SomeTransaction.new.call(arg:"arg")
 => Success({:arg=>"arg"})
2.4.2 :036 > SomeTransaction.new.operations
 => {:some=>nil}

2.4.2 :041 > SomeTransaction.try(:non_existed) #results in adding operations
 => [#<Dry::Transaction::Step:0x00007f8736ad4840 @step_adapter=#<Dry::Transaction::StepAdapters::Raw:0x00007f872b290e28>, @step_name=:some, @operation_name=:some, @operation=nil, @options={}, @call_args=[]>, #<Dry::Transaction::Step:0x00007f8732534d30 @step_adapter=#<Dry::Transaction::StepAdapters::Try:0x00007f872b272db0>, @step_name=:non_existed, @operation_name=:non_existed, @operation=nil, @options={}, @call_args=[]>]

2.4.2 :042 > SomeTransaction.new.operations
 => {:some=>nil, :non_existed=>nil} #Now any call will fail
vanitu commented 6 years ago

sorry. I just understand that try method is overridden on Class methods. closing issue, however think Its bad to override base Ruby methods.

flash-gordon commented 6 years ago

@vanitu FYI there is no try in Ruby, it's just a well-known monkey patch from ActiveSupport. It's sad people confuse it

vanitu commented 6 years ago

@flash-gordon Yes. Its my mistake. ActiveSupport is to deep embedded in daily operations.