Permalink
Browse files

filter refactoring

git-svn-id: https://svn.thoughtbot.com/plugins/when/trunk@317 7bbfaf0e-4d1d-0410-9690-a8bb5f8ef2aa
  • Loading branch information...
1 parent a228c1a commit e73a708b46408d0aa0d3840e8b45991e04e25d86 jcarroll committed Feb 12, 2008
Showing with 46 additions and 16 deletions.
  1. +13 −13 lib/callbacks.rb
  2. +17 −1 lib/filters.rb
  3. +15 −1 lib/validations.rb
  4. +1 −1 lib/when.rb
View
@@ -30,19 +30,19 @@ def #{callback}_with_conditions (*callbacks, &block)
def execute_callback(callback, record, method)
if callback.class == Symbol
record.send callback
- elsif callback.class == String
- eval callback, record.send(:binding)
- elsif callback.class == Proc || callback.class == Method
- callback.call record
- else
- if callback.respond_to?(method)
- callback.send method, record
- else
- raise ActiveRecordError, 'Callbacks must be a symbol denoting the message to send,
- a string to be evaluated, a block to be invoked or a
- class object responding to the callback message
- (#before_create, #after_create, etc).'
- end
+# elsif callback.class == String
+# eval callback, record.send(:binding)
+# elsif callback.class == Proc || callback.class == Method
+# callback.call record
+# else
+# if callback.respond_to?(method)
+# callback.send method, record
+# else
+# raise ActiveRecordError, 'Callbacks must be a symbol denoting the message to send,
+# a string to be evaluated, a block to be invoked or a
+# class object responding to the callback message
+# (#before_create, #after_create, etc).'
+# end
end
end
View
@@ -18,7 +18,7 @@ def #{filter}_with_conditions (*filters, &block)
#{filter}_without_conditions do |controller|
unless (! options[:if].nil? && ! ActiveRecord::Base.evaluate_condition(options[:if], controller)) ||
(! options[:unless].nil? && ActiveRecord::Base.evaluate_condition(options[:unless], controller))
- controller.send filter
+ execute_filter filter, controller, :#{filter}
end
end
end
@@ -28,6 +28,22 @@ def #{filter}_with_conditions (*filters, &block)
class_eval src, __FILE__, __LINE__
end
+ def execute_filter(filter, controller, method)
+ if filter.class == Symbol
+ controller.send filter
+# elsif callback.class == Proc || callback.class == Method
+# callback.call controller
+# else
+# if callback.respond_to?(method)
+# callback.send method, controller
+# else
+# raise ActionControllerError, 'A filter must be a Symbol, Proc, Method, or object
+# responding to filter, after or before.'
+# end
+
+ end
+ end
+
end
end
View
@@ -4,7 +4,7 @@ module Validations
def self.included(klass)
class << klass
- validations = ['validate', 'validate_on_create', 'validate_on_update']
+ validations = ActiveRecord::Validations::VALIDATIONS
validations.each do |validation|
src = <<-END;
@@ -30,6 +30,20 @@ def #{validation}_with_conditions (*validations, &block)
def execute_validation(validation, record, method)
if validation.class == Symbol
record.send validation
+# elsif callback.class == String
+# eval callback, record.send(:binding)
+# elsif callback.class == Proc || callback.class == Method
+# callback.call record
+# else
+# if callback.respond_to?(method)
+# callback.send method, record
+# else
+# raise ActiveRecordError, 'Callbacks must be a symbol denoting the message to send,
+# a string to be evaluated, a block to be invoked or a
+# class object responding to the callback message
+# (#before_create, #after_create, etc).'
+# end
+
end
end
View
@@ -1,6 +1,6 @@
+require File.join(File.dirname(__FILE__), 'callbacks')
require File.join(File.dirname(__FILE__), 'validations')
require File.join(File.dirname(__FILE__), 'filters')
-require File.join(File.dirname(__FILE__), 'callbacks')
ActiveRecord::Base.send :include, ActiveRecordHook::Callbacks
ActiveRecord::Base.send :include, ActiveRecordHook::Validations

0 comments on commit e73a708

Please sign in to comment.