Dry-transaction subclassing, blog example broken


The blog post introducing dry-transaction 0.10 gives an example of how to build a base class to use for one’s own transactions. There are a couple of problems:

  1. typo: self.inherited should be def self.inherited
  2. The new base class’ call ends up higher up in the ancestors list than the included Dry::Transaction module, so it is never invoked.

In sum, this is what I had to do:

class MyTransactionBase
  module InstanceMethods
    def call(input, wrapper_class = nil)
      # custom stuffz

  def self.inherited(klass)
    klass.send :include, Dry::Transaction
    klass.send :prepend, InstanceMethods

Not sure if this should be filed as a bug. If not, maybe the blog post could be updated?

Or maybe I misunderstood something?

Anyway—thanks for dry-rb! It’s changing the way we write code at my job.

You can create a pull request in the dry-rb.org repository (the source file of the blog post is located here).