Module: DatabaseRecorder::ActiveRecord::Recorder
- Defined in:
- lib/database_recorder/active_record/recorder.rb
Class Method Summary collapse
- .ignore_query?(sql, name) ⇒ Boolean
- .record(adapter, sql, name = 'SQL', binds = [], type_casted_binds = [], *args) ⇒ Object
- .setup ⇒ Object
Class Method Details
.ignore_query?(sql, name) ⇒ Boolean
8 9 10 11 12 |
# File 'lib/database_recorder/active_record/recorder.rb', line 8 def ignore_query?(sql, name) !Recording.started? || %w[schema transaction].include?(name&.downcase) || sql.downcase.match?(/\A(begin|commit|release|rollback|savepoint)/i) end |
.record(adapter, sql, name = 'SQL', binds = [], type_casted_binds = [], *args) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/database_recorder/active_record/recorder.rb', line 14 def record(adapter, sql, name = 'SQL', binds = [], type_casted_binds = [], *args) return yield if ignore_query?(sql, name) Core.log_query(sql, name) if Config.replay_recordings && Recording.from_cache Recording.push(sql: sql, binds: binds) data = Recording.cached_query_for(sql) return yield if !data || !data[:result] # cache miss RecordedResult.new(data[:result][:fields], data[:result][:values]) else yield.tap do |result| result_data = if result && (result.respond_to?(:fields) || result.respond_to?(:columns)) fields = result.respond_to?(:fields) ? result.fields : result.columns values = result.respond_to?(:values) ? result.values : result.to_a { count: result.count, fields: fields, values: values } end Recording.push(sql: sql, name: name, binds: type_casted_binds, result: result_data) end end end |
.setup ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/database_recorder/active_record/recorder.rb', line 37 def setup ::ActiveRecord::ConnectionAdapters::AbstractAdapter.class_eval do prepend AbstractAdapterExt end # ::ActiveRecord::Base.class_eval do # prepend BaseExt # end end |