Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

adding block support

git-svn-id: https://svn.thoughtbot.com/plugins/when/trunk@344 7bbfaf0e-4d1d-0410-9690-a8bb5f8ef2aa
  • Loading branch information...
commit 21620772650ee3d94718db5faefd682be99f70d5 1 parent 9b3b500
dcroak authored
Showing with 8 additions and 2 deletions.
  1. +4 −1 lib/callbacks.rb
  2. +4 −1 lib/filters.rb
View
5 lib/callbacks.rb
@@ -9,8 +9,11 @@ class << klass
callbacks.each do |callback|
src = <<-END
- def #{callback}_with_conditions(*callbacks)
+ def #{callback}_with_conditions(*callbacks, &block)
options = callbacks.extract_options!
+ if block_given?
+ callbacks << block
+ end
callbacks.each do |callback|
#{callback}_without_conditions do |record|
unless (! options[:if].nil? && ! evaluate_condition(options[:if], record)) ||
View
5 lib/filters.rb
@@ -7,8 +7,11 @@ class << klass
filters.each do |filter|
src = <<-END
- def #{filter}_with_conditions(*filters)
+ def #{filter}_with_conditions(*filters, &block)
options = filters.extract_options!
+ if block_given?
+ options << block
+ end
filters.each do |filter|
#{filter}_without_conditions(options) do |controller|
unless (! options[:if].nil? && ! ActiveRecord::Base.evaluate_condition(options[:if], controller)) ||
Please sign in to comment.
Something went wrong with that request. Please try again.