Created
May 29, 2010 20:24
-
-
Save julik/418525 to your computer and use it in GitHub Desktop.
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
def create | |
@obj = SomeClass.create(params[:shmoo]) | |
execute_callbacks :on => :shmoo_creation, :with => @obj | |
redirect_to somewhere | |
end | |
def execute_callbacks(options) | |
@callbacks ||= {} | |
event_name = options.delete(:on) | |
if @callbacks[event_name] | |
@callbacks[event_name].each{|c| c.call(options[:with]) } | |
end | |
end | |
def add_callback(on_event, &with_block) | |
@callbacks ||= {} | |
@callbacks[on_event] ||= [] | |
@callbacks << with_block.to_proc | |
end | |
class SomeController << | |
before_filter do | c | | |
get_all_plugins.each do | plugin | | |
plugin.new(c) | |
end | |
end | |
end | |
# А вот это твой плагин | |
class ShmooMailer | |
def initialize(with_controller) | |
with_controller.add_callback(:shmoo_creation) do | shmoo | | |
SuperMailer.deliver_greeting_to_shmoo_owner(shmoo) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment