require 'rom/commands/result'

module ROM
  # Command registry exposes "try" interface for executing commands
  #
  # @api public
  class CommandRegistry < Registry
    include Commands

    # Try to execute a command in a block
    #
    # @yield [command] Passes command to the block
    #
    # @example
    #
    #   rom.command(:users).try { create(name: 'Jane') }
    #   rom.command(:users).try { update(:by_id, 1).set(name: 'Jane Doe') }
    #   rom.command(:users).try { delete(:by_id, 1) }
    #
    #   rom.command(:users).try { |command| command.create(name: 'Jane') }
    #   rom.command(:users).try { |command| command.delete(:by_id, 1) }
    #
    # @return [Commands::Result]
    #
    # @api public
    def try(&block)
      response = block.call

      if response.is_a?(Command) || response.is_a?(Composite)
        try { response.call }
      else
        Result::Success.new(response)
      end
    rescue CommandError => e
      Result::Failure.new(e)
    end
  end
end

require 'rom/commands/result'

module ROM
  # Command registry exposes "try" interface for executing commands
  #
  # @api public
  class CommandRegistry < Registry
    include Commands

    # Try to execute a command in a block
    #
    # @yield [command] Passes command to the block
    #
    # @example
    #
    #   rom.command(:users).try { create(name: 'Jane') }
    #   rom.command(:users).try { update(:by_id, 1).set(name: 'Jane Doe') }
    #   rom.command(:users).try { delete(:by_id, 1) }
    #
    # @return [Commands::Result]
    #
    # @api public
    def try(&block)
      response = block.call

      if response.is_a?(Command) || response.is_a?(Composite)
        try { response.call }
      else
        Result::Success.new(response)
      end
    rescue CommandError => e
      Result::Failure.new(e)
    end
  end
end

Remove obsolete usage of CommandRegistry
Remove obsolete usage of CommandRegistry

Passing argument to the block was removed in 63d6e1316.

[ci skip]
