Skip to content

Instantly share code, notes, and snippets.

@hadees
Created July 19, 2012 19:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hadees/3146032 to your computer and use it in GitHub Desktop.
Save hadees/3146032 to your computer and use it in GitHub Desktop.
Observer
class UserObserver < ActiveRecord::Observer
include OverAchievement
level_up :foobar, on: [:after_save, :before_create] do
if user.is_active?
end
end
module OverAchievement
def level_up(level, *args, &block)
options = args.extract_options!
options[:on] = options[:on].to_a
options[:on].each do |callback|
defined_levels[callback] ||= []
defined_levels[callback] << block
end
def defined_levels
@defined_levels ||= {}
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment