Readme.md in lazy_observers-0.0.4 vs Readme.md in lazy_observers-0.1.0
- old
+ new
@@ -1,9 +1,25 @@
Make Activerecord Observers not load observed models -> faster/safer environment boot.
- faster tests + console
- able to boot environment without/with empty/with old database
+Recommended: turn your observers into modules
+
+```Ruby
+module CachingObserver
+ def self.included(base)
+ this = self
+ base.after_save { |record| this.do_something(record); true }
+ end
+
+ def self.do_something(record)
+ ... do something ...
+ end
+end
+```
+
+
Install
=======
gem install lazy_observers
@@ -17,11 +33,11 @@
end
### Extend models from gems after they are loaded
LazyObservers.on_load("Arturo::Feature") do |klass|
- Arturo::Feature.class_eval do
+ klass.class_eval do
... funky hacks ...
end
end
### Catch models that are loaded in application startup.
@@ -37,9 +53,10 @@
LazyObservers.check_classes
TIPS
====
+ - .on_load is called before all methods are defined on the baseclass, so they might not be defined
- do not use observe and lazy_observe in the same observer (and if you have to, use observe after lay_observe)
- do not use Model classes with class-methods of the observer e.g. class FooObserver; Foo.something{}; def after_update; end; end
Author
======