Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use send instead of instance_eval

  • Loading branch information...
commit 5ce3831faf684aea75948ce4602b6b9de361c11e 1 parent b7052b8
@lifo lifo authored
View
6 activemodel/lib/active_model/errors.rb
@@ -68,7 +68,7 @@ def add(attribute, message = nil, options = {})
# 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 @@ def add_on_empty(attributes, custom_message = nil)
# 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 @@ def generate_message(attribute, message = :invalid, options = {})
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,
View
2  activemodel/lib/active_model/validations.rb
@@ -66,7 +66,7 @@ def validates_each(*attrs)
# 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
Please sign in to comment.
Something went wrong with that request. Please try again.