class Rack::CsrfDetector::ActiveRecordInstrument

Public Instance Methods

use!() click to toggle source
# File lib/rack/csrf_detector/active_record_instrument.rb, line 2
def use!
  require 'active_record/connection_adapters/abstract/transaction'

  if ActiveRecord::VERSION::STRING.match(/^4.2/)
    🙉_activerecord_4_2!
  else
    🙉_activerecord_4_0!
  end
end

Private Instance Methods

🙉_activerecord_4_0!() click to toggle source
# File lib/rack/csrf_detector/active_record_instrument.rb, line 14
def 🙉_activerecord_4_0!
  ActiveRecord::ConnectionAdapters::OpenTransaction.class_eval do
    commit_method = instance_method(:commit)

    define_method :commit do
      Rack::CsrfDetector.more_bad!
      commit_method.bind(self).call
    end
  end
end
🙉_activerecord_4_2!() click to toggle source
# File lib/rack/csrf_detector/active_record_instrument.rb, line 25
def 🙉_activerecord_4_2!
  ActiveRecord::ConnectionAdapters::Transaction.class_eval do
    commit_method = instance_method(:commit)

    define_method :commit do
      Rack::CsrfDetector.more_bad!
      commit_method.bind(self).call
    end
  end
end