module DatabaseRewinder::InsertRecorder

Public Class Methods

prepended(mod) click to toggle source

This method actually no longer has to be a ‘prepended` hook because InsertRecorder is a module without a direct method now, but still doing this just for compatibility

# File lib/database_rewinder/active_record_monkey.rb, line 6
    def self.prepended(mod)
      [:execute, :exec_query, :internal_exec_query].each do |method_name|
        if mod.instance_methods.include?(method_name) && (meth = mod.instance_method(method_name))
          method_body = if meth.parameters.any? {|type, _name| [:key, :keyreq, :keyrest].include? type }
            <<-RUBY
              def #{method_name}(sql, *, **)
                DatabaseRewinder.record_inserted_table self, sql
                super
              end
            RUBY
          else
            <<-RUBY
              def #{method_name}(sql, *)
                DatabaseRewinder.record_inserted_table self, sql
                super
              end
            RUBY
          end

          mod.send :prepend, Module.new { class_eval method_body }
        end
      end
    end