aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2009-08-06 00:11:28 +0100
committerPratik Naik <pratiknaik@gmail.com>2009-08-06 00:11:28 +0100
commit5ce3831faf684aea75948ce4602b6b9de361c11e (patch)
tree8a0910d94693a7b9aa5e8035f90016c7bb9a1746 /activemodel
parentb7052b8dc33d5769e94dfcec62d439c2dd18a8b9 (diff)
downloadrails-5ce3831faf684aea75948ce4602b6b9de361c11e.tar.gz
rails-5ce3831faf684aea75948ce4602b6b9de361c11e.tar.bz2
rails-5ce3831faf684aea75948ce4602b6b9de361c11e.zip
Use send instead of instance_eval
Diffstat (limited to 'activemodel')
-rw-r--r--activemodel/lib/active_model/errors.rb6
-rw-r--r--activemodel/lib/active_model/validations.rb2
2 files changed, 4 insertions, 4 deletions
diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb
index a47d89ac0e..7a3001174f 100644
--- a/activemodel/lib/active_model/errors.rb
+++ b/activemodel/lib/active_model/errors.rb
@@ -68,7 +68,7 @@ module ActiveModel
# Will add an error message to each of the attributes in +attributes+ that is empty.
def add_on_empty(attributes, custom_message = nil)
[attributes].flatten.each do |attribute|
- value = @base.instance_eval { read_attribute_for_validation(attribute) }
+ value = @base.send(:read_attribute_for_validation, attribute)
is_empty = value.respond_to?(:empty?) ? value.empty? : false
add(attribute, :empty, :default => custom_message) unless !value.nil? && !is_empty
end
@@ -77,7 +77,7 @@ module ActiveModel
# Will add an error message to each of the attributes in +attributes+ that is blank (using Object#blank?).
def add_on_blank(attributes, custom_message = nil)
[attributes].flatten.each do |attribute|
- value = @base.instance_eval { read_attribute_for_validation(attribute) }
+ value = @base.send(:read_attribute_for_validation, attribute)
add(attribute, :blank, :default => custom_message) if value.blank?
end
end
@@ -146,7 +146,7 @@ module ActiveModel
defaults = defaults.compact.flatten << :"messages.#{message}"
key = defaults.shift
- value = @base.instance_eval { read_attribute_for_validation(attribute) }
+ value = @base.send(:read_attribute_for_validation, attribute)
options = { :default => defaults,
:model => @base.class.name.humanize,
diff --git a/activemodel/lib/active_model/validations.rb b/activemodel/lib/active_model/validations.rb
index 0fca96e5cc..7d49e60790 100644
--- a/activemodel/lib/active_model/validations.rb
+++ b/activemodel/lib/active_model/validations.rb
@@ -66,7 +66,7 @@ module ActiveModel
# Declare the validation.
send(validation_method(options[:on]), options) do |record|
attrs.each do |attr|
- value = record.instance_eval { read_attribute_for_validation(attr) }
+ value = record.send(:read_attribute_for_validation, attr)
next if (value.nil? && options[:allow_nil]) || (value.blank? && options[:allow_blank])
yield record, attr, value
end