class DatabaseLeakFinder::Finder
Constants
- IGNORED_SYSTEM_TABLES
Public Class Methods
new(options)
click to toggle source
# File lib/database_leak_finder/finder.rb, line 5 def initialize(options) @ignored_tables = (options[:ignored_tables] || []).map(&:to_s) + IGNORED_SYSTEM_TABLES end
Public Instance Methods
process()
click to toggle source
# File lib/database_leak_finder/finder.rb, line 9 def process return [] unless ActiveRecord::Base.connected? filtered_tables.each_with_object({}) do |table, result| amount = count_for(table) result[table] = amount unless amount.zero? result end end
Private Instance Methods
count_for(table)
click to toggle source
# File lib/database_leak_finder/finder.rb, line 19 def count_for(table) ActiveRecord::Base.connection.select_value("SELECT COUNT(*) FROM #{table}").to_i rescue raise StandardError, "An error occurred while try to count '#{table}'" end
filtered_tables()
click to toggle source
# File lib/database_leak_finder/finder.rb, line 25 def filtered_tables tables - @ignored_tables end
tables()
click to toggle source
# File lib/database_leak_finder/finder.rb, line 29 def tables ActiveRecord::Base.connection.data_sources end