Class: ActiveRecord::SQLCounter

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record/test_case.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ignore = Regexp.union(self.class.ignored_sql)) ⇒ SQLCounter

Returns a new instance of SQLCounter.



106
107
108
# File 'lib/active_record/test_case.rb', line 106

def initialize(ignore = Regexp.union(self.class.ignored_sql))
  @ignore = ignore
end

Class Attribute Details

.ignored_sqlObject

Returns the value of attribute ignored_sql.



84
85
86
# File 'lib/active_record/test_case.rb', line 84

def ignored_sql
  @ignored_sql
end

.logObject

Returns the value of attribute log.



84
85
86
# File 'lib/active_record/test_case.rb', line 84

def log
  @log
end

.log_allObject

Returns the value of attribute log_all.



84
85
86
# File 'lib/active_record/test_case.rb', line 84

def log_all
  @log_all
end

Instance Attribute Details

#ignoreObject (readonly)

Returns the value of attribute ignore.



104
105
106
# File 'lib/active_record/test_case.rb', line 104

def ignore
  @ignore
end

Class Method Details

.clear_logObject



85
# File 'lib/active_record/test_case.rb', line 85

def clear_log; self.log = []; self.log_all = []; end

Instance Method Details

#call(name, start, finish, message_id, values) ⇒ Object



110
111
112
113
114
115
116
117
118
119
# File 'lib/active_record/test_case.rb', line 110

def call(name, start, finish, message_id, values)
  sql = values[:sql]

  # FIXME: this seems bad. we should probably have a better way to indicate
  # the query was cached
  return if 'CACHE' == values[:name]

  self.class.log_all << sql
  self.class.log << sql unless ignore =~ sql
end