Skip to content

Instantly share code, notes, and snippets.

@julik
Created May 29, 2010 20:24
Show Gist options
  • Save julik/418525 to your computer and use it in GitHub Desktop.
Save julik/418525 to your computer and use it in GitHub Desktop.
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