Sha256: edc32dfc4c68d88a40805650712b90ea5eeff3b3ad78a24f807172da66ad5bd3

Contents?: true

Size: 845 Bytes

Versions: 20

Compression:

Stored size: 845 Bytes

Contents

require "active_record"

module NulogyGraphqlApi
  class TransactionService
    def execute_in_transaction
      context = Transaction.new
      result = nil
      ActiveRecord::Base.transaction(requires_new: true, joinable: false) do
        result = yield(context)
        raise ActiveRecord::Rollback if context.rolledback?
      end
      result
    end

    class Transaction
      def initialize
        @rollback = false
      end

      def rollback
        @rollback = true
      end

      def rolledback?
        @rollback
      end
    end

    # TODO: Move to the spec folder
    class Dummy
      attr_reader :transaction

      def execute_in_transaction
        @transaction = Transaction.new
        @was_called = true
        yield(@transaction)
      end

      def was_called?
        @was_called
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
nulogy_graphql_api-4.3.0 lib/nulogy_graphql_api/transaction_service.rb
nulogy_graphql_api-4.2.0 lib/nulogy_graphql_api/transaction_service.rb
nulogy_graphql_api-4.1.0 lib/nulogy_graphql_api/transaction_service.rb
nulogy_graphql_api-4.0.0 lib/nulogy_graphql_api/transaction_service.rb
nulogy_graphql_api-3.0.1 lib/nulogy_graphql_api/transaction_service.rb
nulogy_graphql_api-2.2.0 lib/nulogy_graphql_api/transaction_service.rb
nulogy_graphql_api-2.1.3 lib/nulogy_graphql_api/transaction_service.rb
nulogy_graphql_api-2.1.2 lib/nulogy_graphql_api/transaction_service.rb
nulogy_graphql_api-2.1.1 lib/nulogy_graphql_api/transaction_service.rb
nulogy_graphql_api-2.1.0 lib/nulogy_graphql_api/transaction_service.rb
nulogy_graphql_api-2.0.1 lib/nulogy_graphql_api/transaction_service.rb
nulogy_graphql_api-2.0.0 lib/nulogy_graphql_api/transaction_service.rb
nulogy_graphql_api-1.1.1 lib/nulogy_graphql_api/transaction_service.rb
nulogy_graphql_api-1.1.0 lib/nulogy_graphql_api/transaction_service.rb
nulogy_graphql_api-1.0.0 lib/nulogy_graphql_api/transaction_service.rb
nulogy_graphql_api-0.6.0 lib/nulogy_graphql_api/transaction_service.rb
nulogy_graphql_api-0.5.3 lib/nulogy_graphql_api/transaction_service.rb
nulogy_graphql_api-0.5.1 lib/nulogy_graphql_api/transaction_service.rb
nulogy_graphql_api-0.5.0 lib/nulogy_graphql_api/transaction_service.rb
nulogy_graphql_api-0.4.0 lib/nulogy_graphql_api/transaction_service.rb