Created
July 19, 2012 19:02
-
-
Save hadees/3146032 to your computer and use it in GitHub Desktop.
Observer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UserObserver < ActiveRecord::Observer | |
include OverAchievement | |
level_up :foobar, on: [:after_save, :before_create] do | |
if user.is_active? | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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