module Formalism::SequelTransactions

Main module which should be included into base form

Constants

TRANSACTION_OPTIONS
VERSION

Public Class Methods

new(*) click to toggle source
Calls superclass method
# File lib/formalism/sequel_transactions.rb, line 10
def initialize(*)
        @ran_times = 0

        super
end

Public Instance Methods

before_retry() click to toggle source
# File lib/formalism/sequel_transactions.rb, line 24
def before_retry
        nested_forms.each_value(&__method__)

        @filled_fields_and_nested_forms.clear

        fill_fields_and_nested_forms
end
run() click to toggle source
# File lib/formalism/sequel_transactions.rb, line 16
def run
        return unless runnable

        result = db_connection.in_transaction? ? run_without_transaction.last : run_with_transaction

        Form::Outcome.new(errors, result)
end

Private Instance Methods

run_with_transaction() click to toggle source
# File lib/formalism/sequel_transactions.rb, line 39
def run_with_transaction
        db_connection.transaction(**TRANSACTION_OPTIONS) do
                db_connection.after_commit { after_db_transaction_commit }

                is_valid, result = run_without_transaction

                raise Sequel::Rollback unless is_valid

                result
        end
end
run_without_transaction() click to toggle source
# File lib/formalism/sequel_transactions.rb, line 51
def run_without_transaction
        before_retry if (@ran_times += 1) > 1

        is_valid = valid?

        [is_valid, (execute if is_valid)]
end