1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Privatize unneededly protected methods in Active Model

This commit is contained in:
Akira Matsuda 2016-12-19 18:41:09 +09:00
parent 53f537d1f8
commit cdb9d7f481
6 changed files with 23 additions and 27 deletions

View file

@ -334,12 +334,11 @@ module ActiveModel
}.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 @@ module ActiveModel
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)

View file

@ -15,7 +15,7 @@ module ActiveModel
end
module ForbiddenAttributesProtection # :nodoc:
protected
private
def sanitize_for_mass_assignment(attributes)
if attributes.respond_to?(:permitted?)
raise ActiveModel::ForbiddenAttributesError if !attributes.permitted?

View file

@ -399,14 +399,14 @@ module ActiveModel
# 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

View file

@ -104,10 +104,10 @@ module ActiveModel
end
end
protected
private
# Overwrite run validations to include callbacks.
def run_validations! #:nodoc:
def run_validations!
_run_validation_callbacks { super }
end
end

View file

@ -61,29 +61,29 @@ module ActiveModel
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 @@ module ActiveModel
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

View file

@ -148,15 +148,15 @@ module ActiveModel
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
{}