class ArQueryMatchers::Queries::LoadCounter::LoadQueryFilter
Constants
- MODEL_LOAD_PATTERN
Matches named SQL operations like the following: 'User Load'
- MODEL_SQL_PATTERN
Matches unnamed SQL operations like the following: “SELECT COUNT(*) FROM `users` …”
Public Instance Methods
filter_map(name, sql)
click to toggle source
# File lib/ar_query_matchers/queries/load_counter.rb, line 26 def filter_map(name, sql) # First check for a `SELECT * FROM` query that ActiveRecord has # helpfully named for us in the payload match = name.match(MODEL_LOAD_PATTERN) return ModelName.new(match[:model_name]) if match # Fall back to pattern-matching on the table name in a COUNT and looking # up the table name from ActiveRecord's loaded descendants. select_from_table = sql.match(MODEL_SQL_PATTERN) TableName.new(select_from_table[:table_name]) if select_from_table end