Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Per-Instance Callbacks

#775

This patch allows callbacks to be hooked up on an individual instance.


class SomeStorage
  include ActiveSupport::Callbacks
  define_callbacks :before_save, :after_save
  def save
    run_callbacks(:before_save)
    puts "- save"
    run_callbacks(:after_save)
  end
end

store = SomeStorage.new

store.before_save do |object|
  puts "saving..."
end

store.after_save do |object|
  puts "saved."
end

store.save

#
# Output:
#   saving...
#   - save
#   saved

Reported by Tom Lea · August 7th, 2008 @ 06:13 PM

State: invalid
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. Tom Lea
    Tom Lea

    Hmm, this clashes with the way AR callbacks work... works for none AR apps using ActiveSupport (where the patch was developed), but not so much for Rails...

    Ignore the patch.

    August 7th, 2008 @ 07:08 PM

  2. Jeremy Kemper
    Jeremy Kemper
    • State changed from new to invalid

    August 7th, 2008 @ 07:19 PM