提交 cdb9d7f4 编写于 作者: A Akira Matsuda

Privatize unneededly protected methods in Active Model

上级 53f537d1
......@@ -334,12 +334,11 @@ def generated_attribute_methods #:nodoc:
}.tap { |mod| include mod }
end
protected
def instance_method_already_implemented?(method_name) #:nodoc:
private
def instance_method_already_implemented?(method_name)
generated_attribute_methods.method_defined?(method_name)
end
private
# The methods +method_missing+ and +respond_to?+ of this module are
# invoked often in a typical rails, both of which invoke the method
# +matched_attribute_method+. The latter method iterates through an
......@@ -458,12 +457,11 @@ def respond_to?(method, include_private_methods = false)
end
end
protected
def attribute_method?(attr_name) #:nodoc:
private
def attribute_method?(attr_name)
respond_to_without_attributes?(:attributes) && attributes.include?(attr_name)
end
private
# Returns a struct representing the matching attribute method.
# The struct's attributes are prefix, base and suffix.
def matched_attribute_method(method_name)
......
......@@ -15,7 +15,7 @@ class ForbiddenAttributesError < StandardError
end
module ForbiddenAttributesProtection # :nodoc:
protected
private
def sanitize_for_mass_assignment(attributes)
if attributes.respond_to?(:permitted?)
raise ActiveModel::ForbiddenAttributesError if !attributes.permitted?
......
......@@ -399,14 +399,14 @@ def validate!(context = nil)
# end
alias :read_attribute_for_validation :send
protected
private
def run_validations! #:nodoc:
def run_validations!
_run_validate_callbacks
errors.empty?
end
def raise_validation_error
def raise_validation_error # :doc:
raise(ValidationError.new(self))
end
end
......
......@@ -104,10 +104,10 @@ def after_validation(*args, &block)
end
end
protected
private
# Overwrite run validations to include callbacks.
def run_validations! #:nodoc:
def run_validations!
_run_validation_callbacks { super }
end
end
......
......@@ -61,29 +61,29 @@ def validate_each(record, attr_name, value)
end
end
protected
private
def is_number?(raw_value)
def is_number?(raw_value) # :doc:
!parse_raw_value_as_a_number(raw_value).nil?
rescue ArgumentError, TypeError
false
end
def parse_raw_value_as_a_number(raw_value)
def parse_raw_value_as_a_number(raw_value) # :doc:
Kernel.Float(raw_value) if raw_value !~ /\A0[xX]/
end
def is_integer?(raw_value)
def is_integer?(raw_value) # :doc:
/\A[+-]?\d+\z/ === raw_value.to_s
end
def filtered_options(value)
def filtered_options(value) # :doc:
filtered = options.except(*RESERVED_OPTIONS)
filtered[:value] = value
filtered
end
def allow_only_integer?(record)
def allow_only_integer?(record) # :doc:
case options[:only_integer]
when Symbol
record.send(options[:only_integer])
......@@ -94,12 +94,10 @@ def allow_only_integer?(record)
end
end
private
def record_attribute_changed_in_place?(record, attr_name)
record.respond_to?(:attribute_changed_in_place?) &&
record.attribute_changed_in_place?(attr_name.to_s)
end
def record_attribute_changed_in_place?(record, attr_name)
record.respond_to?(:attribute_changed_in_place?) &&
record.attribute_changed_in_place?(attr_name.to_s)
end
end
module HelperMethods
......
......@@ -148,15 +148,15 @@ def validates!(*attributes)
validates(*(attributes << options))
end
protected
private
# When creating custom validators, it might be useful to be able to specify
# additional default keys. This can be done by overwriting this method.
def _validates_default_keys # :nodoc:
def _validates_default_keys
[:if, :unless, :on, :allow_blank, :allow_nil , :strict]
end
def _parse_validates_options(options) # :nodoc:
def _parse_validates_options(options)
case options
when TrueClass
{}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册