lib/lazy_observers.rb in lazy_observers-0.1.0 vs lib/lazy_observers.rb in lazy_observers-0.2.0

- old
+ new

@@ -1,8 +1,8 @@ require 'lazy_observers/version' require 'active_record' -require 'active_record/observer' +require 'lazy_observers/rails_observer' require 'lazy_observers/railtie' if defined?(Rails) module LazyObservers def self.observed_loaded(klass) class_name = klass.name @@ -85,11 +85,10 @@ super end end end -descendants = (ActiveRecord::VERSION::MAJOR > 2 ? :descendants : :subclasses) -ActiveRecord::Base.send(descendants).each{|klass| LazyObservers.observed_loaded(klass) } +ActiveRecord::Base.send(:descendants).each{|klass| LazyObservers.observed_loaded(klass) } ActiveRecord::Observer.class_eval do def self.lazy_observe(*classes) raise "pass class names, not classes or symbols!" unless classes.all?{|klass| klass.is_a?(String) } define_method(:observed_classes) { Set.new } # prevent default of PostObserver -> Post