Module: TPhases::Modes::Helpers::TransactionalViolationsHelper::ClassMethods

Defined in:
lib/tphases/modes/helpers/transactional_violations_helper.rb

Instance Method Summary collapse

Instance Method Details

#define_phase_methods!Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/tphases/modes/helpers/transactional_violations_helper.rb', line 23

def define_phase_methods!
  %w{read write no_transactions}.each do |phase_type|
    define_singleton_method(:"#{phase_type}_phase") do |&block|

      if @phase_stack.last.try(:ignored?)
        return block.call
      end

      phase = Phase.new
      @phase_stack << phase
      begin
        subscriber = ActiveSupport::Notifications.subscribe("sql.active_record") do |name, date, date2, sha, args|
          next unless @phase_stack.last == phase
          send(:"#{phase_type}_violation_action", args[:sql], caller) if send(:"#{phase_type}_violation?", args[:sql])
        end
        return block.call
      ensure
        ActiveSupport::Notifications.unsubscribe(subscriber)
        @phase_stack.pop
      end
    end
  end
end

#ignore_phasesObject



47
48
49
50
51
52
# File 'lib/tphases/modes/helpers/transactional_violations_helper.rb', line 47

def ignore_phases
  @phase_stack << Phase.new(ignore: true)
  yield
ensure
  @phase_stack.pop
end