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.



79
80
81
# File 'lib/active_record/test_case.rb', line 79

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

Class Attribute Details

.ignored_sqlObject

Returns the value of attribute ignored_sql.



57
58
59
# File 'lib/active_record/test_case.rb', line 57

def ignored_sql
  @ignored_sql
end

.logObject

Returns the value of attribute log.



57
58
59
# File 'lib/active_record/test_case.rb', line 57

def log
  @log
end

.log_allObject

Returns the value of attribute log_all.



57
58
59
# File 'lib/active_record/test_case.rb', line 57

def log_all
  @log_all
end

Instance Attribute Details

#ignoreObject (readonly)

Returns the value of attribute ignore.



77
78
79
# File 'lib/active_record/test_case.rb', line 77

def ignore
  @ignore
end

Class Method Details

.clear_logObject



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

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

Instance Method Details

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



83
84
85
86
87
88
89
90
91
92
# File 'lib/active_record/test_case.rb', line 83

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