class ConsistencyFail::Enforcer
Public Class Methods
enforce!()
click to toggle source
# File lib/consistency_fail/enforcer.rb, line 13 def self.enforce! models = ConsistencyFail::Models.new($LOAD_PATH) models.preload_all introspectors = [ConsistencyFail::Introspectors::ValidatesUniquenessOf.new, ConsistencyFail::Introspectors::HasOne.new, ConsistencyFail::Introspectors::Polymorphic.new] problem_models_exist = models.all.detect do |model| introspectors.any? {|i| !i.missing_indexes(model).empty?} end if problem_models_exist mega_fail! end end
find(*arguments)
click to toggle source
# File lib/consistency_fail/enforcer.rb, line 37 def find(*arguments) panic end
mega_fail!()
click to toggle source
# File lib/consistency_fail/enforcer.rb, line 30 def self.mega_fail! ActiveRecord::Base.class_eval do class << self def panic raise "You've got missing indexes! Run `consistency_fail` to find and fix them." end def find(*arguments) panic end alias :first :find alias :last :find alias :count :find end def save(*arguments) self.class.panic end def save!(*arguments) self.class.panic end end end
panic()
click to toggle source
# File lib/consistency_fail/enforcer.rb, line 33 def panic raise "You've got missing indexes! Run `consistency_fail` to find and fix them." end
Public Instance Methods
problems(models, introspector)
click to toggle source
# File lib/consistency_fail/enforcer.rb, line 5 def problems(models, introspector) problems = models.map do |m| [m, introspector.missing_indexes(m)] end.reject do |m, indexes| indexes.empty? end end
save(*arguments)
click to toggle source
# File lib/consistency_fail/enforcer.rb, line 46 def save(*arguments) self.class.panic end
save!(*arguments)
click to toggle source
# File lib/consistency_fail/enforcer.rb, line 50 def save!(*arguments) self.class.panic end