Sha256: 6900cf8e80d1f00b06b2f3f789f7db053694b8a08d461e5bbeb8e17a15121f79

Contents?: true

Size: 684 Bytes

Versions: 4

Compression:

Stored size: 684 Bytes

Contents

require_relative "invalid"

module Hexx
  class Service

    # Declares the <tt>##transaction</tt> private instance method.
    module Transactions
      include Wisper::Publisher

      private

      # Yields the block and publishes :error notification with
      # error messages in case of any standard exception being raised.
      def transaction
        run_and_rescue do
          validate!
          yield
        end
      end

      def run_and_rescue
        yield
      rescue Service::Invalid => err
        publish :error, Message.from(err.service)
      rescue => err
        publish :error, [Message.new(type: "error", text: err.message)]
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
hexx-2.2.0 lib/hexx/service/transactions.rb
hexx-2.1.0 lib/hexx/service/transactions.rb
hexx-2.0.2 lib/hexx/service/transactions.rb
hexx-2.0.1 lib/hexx/service/transactions.rb