diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-06-11 10:20:29 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-06-11 10:20:29 -0700 |
commit | a63a964a5d1ed02cf0df1b1a33a96ed2a9fa987b (patch) | |
tree | 1eea1b0e20ba751aeaeacbddf3b57d16f63a4219 /activemodel | |
parent | ebf2113a0565d2e38802f29291b3971b2c7f7922 (diff) | |
download | rails-a63a964a5d1ed02cf0df1b1a33a96ed2a9fa987b.tar.gz rails-a63a964a5d1ed02cf0df1b1a33a96ed2a9fa987b.tar.bz2 rails-a63a964a5d1ed02cf0df1b1a33a96ed2a9fa987b.zip |
remove some evals from callback conditionals
Diffstat (limited to 'activemodel')
-rw-r--r-- | activemodel/lib/active_model/callbacks.rb | 5 | ||||
-rw-r--r-- | activemodel/lib/active_model/validations.rb | 4 |
2 files changed, 7 insertions, 2 deletions
diff --git a/activemodel/lib/active_model/callbacks.rb b/activemodel/lib/active_model/callbacks.rb index 8b09f8b203..377aa6ee27 100644 --- a/activemodel/lib/active_model/callbacks.rb +++ b/activemodel/lib/active_model/callbacks.rb @@ -135,7 +135,10 @@ module ActiveModel klass.define_singleton_method("after_#{callback}") do |*args, &block| options = args.extract_options! options[:prepend] = true - options[:if] = Array(options[:if]) << "value != false" + conditional = ActiveSupport::Callbacks::Conditionals::Value.new { |v| + v != false + } + options[:if] = Array(options[:if]) << conditional set_callback(:"#{callback}", :after, *(args << options), &block) end end diff --git a/activemodel/lib/active_model/validations.rb b/activemodel/lib/active_model/validations.rb index cb1db1e5aa..31c2245265 100644 --- a/activemodel/lib/active_model/validations.rb +++ b/activemodel/lib/active_model/validations.rb @@ -142,7 +142,9 @@ module ActiveModel if options.key?(:on) options = options.dup options[:if] = Array(options[:if]) - options[:if].unshift("validation_context == :#{options[:on]}") + options[:if].unshift lambda { |o| + o.validation_context == options[:on] + } end args << options set_callback(:validate, *args, &block) |