Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

lazy_observers

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lazy_observers

  • 0.2.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

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

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

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

FAQs

Package last updated on 02 Sep 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc