aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model/callbacks.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2013-05-17 12:01:30 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2013-05-17 12:01:30 -0700
commitf796ed6088ab1e347fcfe573a6346d1235453156 (patch)
tree81c7e25d21ac4dd5f26bd3c6ca91f8d0be7c2cbf /activemodel/lib/active_model/callbacks.rb
parenteaf54865b1313094ffca16aca1b199394bc58bae (diff)
parent677b64fcd527529390e232ceedf8fa8bfac224e2 (diff)
downloadrails-f796ed6088ab1e347fcfe573a6346d1235453156.tar.gz
rails-f796ed6088ab1e347fcfe573a6346d1235453156.tar.bz2
rails-f796ed6088ab1e347fcfe573a6346d1235453156.zip
Merge branch 'master' into stmt
* master: (330 commits) plugin new missing license spec let Ruby do the is_a check for us Mocha 0.14.0 was released with MT5 support. Switch back to gem Fix named routing regression from 3.2.13 Revert "just call the class method since we know the callbacks are stored at the" test refactor Add more data to AR::UnknownAttributeError Raise when multiple included blocks are defined Revert "Integration tests support the OPTIONS http method" restore whitespace in Gemfile between sqlite3 and sprockets Revert "Add the options method to action_controller testcase." Check if APP_RAKEFILE is defined Fix detection of engine in rake db:load_config Broken by d1d7c86d0c8dcb7e75a87644b330c4e9e7d6c1c1 Remove trailing line break tiny types should only be integers when the length is <= 1. fixes #10620 add failing test exposing mysql adapter tinyint bug require things we need Revert "Merge pull request #10600 from aditya-kapoor/code_refactor" just call the class method since we know the callbacks are stored at the class level this variable is used, so we don't have to use double assignments ...
Diffstat (limited to 'activemodel/lib/active_model/callbacks.rb')
-rw-r--r--activemodel/lib/active_model/callbacks.rb38
1 files changed, 16 insertions, 22 deletions
diff --git a/activemodel/lib/active_model/callbacks.rb b/activemodel/lib/active_model/callbacks.rb
index b5562dda2e..8b09f8b203 100644
--- a/activemodel/lib/active_model/callbacks.rb
+++ b/activemodel/lib/active_model/callbacks.rb
@@ -100,10 +100,10 @@ module ActiveModel
def define_model_callbacks(*callbacks)
options = callbacks.extract_options!
options = {
- :terminator => "result == false",
- :skip_after_callbacks_if_terminated => true,
- :scope => [:kind, :name],
- :only => [:before, :around, :after]
+ terminator: ->(_,result) { result == false },
+ skip_after_callbacks_if_terminated: true,
+ scope: [:kind, :name],
+ only: [:before, :around, :after]
}.merge!(options)
types = Array(options.delete(:only))
@@ -120,30 +120,24 @@ module ActiveModel
private
def _define_before_model_callback(klass, callback) #:nodoc:
- klass.class_eval <<-CALLBACK, __FILE__, __LINE__ + 1
- def self.before_#{callback}(*args, &block)
- set_callback(:#{callback}, :before, *args, &block)
- end
- CALLBACK
+ klass.define_singleton_method("before_#{callback}") do |*args, &block|
+ set_callback(:"#{callback}", :before, *args, &block)
+ end
end
def _define_around_model_callback(klass, callback) #:nodoc:
- klass.class_eval <<-CALLBACK, __FILE__, __LINE__ + 1
- def self.around_#{callback}(*args, &block)
- set_callback(:#{callback}, :around, *args, &block)
- end
- CALLBACK
+ klass.define_singleton_method("around_#{callback}") do |*args, &block|
+ set_callback(:"#{callback}", :around, *args, &block)
+ end
end
def _define_after_model_callback(klass, callback) #:nodoc:
- klass.class_eval <<-CALLBACK, __FILE__, __LINE__ + 1
- def self.after_#{callback}(*args, &block)
- options = args.extract_options!
- options[:prepend] = true
- options[:if] = Array(options[:if]) << "value != false"
- set_callback(:#{callback}, :after, *(args << options), &block)
- end
- CALLBACK
+ klass.define_singleton_method("after_#{callback}") do |*args, &block|
+ options = args.extract_options!
+ options[:prepend] = true
+ options[:if] = Array(options[:if]) << "value != false"
+ set_callback(:"#{callback}", :after, *(args << options), &block)
+ end
end
end
end