Skip to content

grosser/lazy_observers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DEPREACTED ... kill observers instead!

Make Activerecord Observers not load observed models -> faster/safer environment boot.

  • faster tests + console
  • able to boot environment without/with empty/with old database

Install

gem install lazy_observers

Usage

class FooObserver < ActiveRecord::Observer
  lazy_observe "User", "Foo::Bar"

  ...
end

Extend models from gems after they are loaded

LazyObservers.on_load("Arturo::Feature") do |klass|
  klass.class_eval do
    ... funky hacks ...
  end
end

Catch models that are loaded in application startup.

LazyObservers.debug_active_record_loading

script/console or rails c

Verify you did not misspell

Loads all classes registered via observers, to make sure you did not misspell
(negates the effect of lazyness, so only use for debugging)

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

Michael Grosser
michael@grosser.it
License: MIT
Build Status

About

Make Activerecord Observers not load observed models -> faster/safer environment boot

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages