Skip to content

Commit cdb9d7f

Browse files
committed
Privatize unneededly protected methods in Active Model
1 parent 53f537d commit cdb9d7f

File tree

6 files changed

+23
-27
lines changed

6 files changed

+23
-27
lines changed

activemodel/lib/active_model/attribute_methods.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -334,12 +334,11 @@ def generated_attribute_methods #:nodoc:
334334
}.tap { |mod| include mod }
335335
end
336336

337-
protected
338-
def instance_method_already_implemented?(method_name) #:nodoc:
337+
private
338+
def instance_method_already_implemented?(method_name)
339339
generated_attribute_methods.method_defined?(method_name)
340340
end
341341

342-
private
343342
# The methods +method_missing+ and +respond_to?+ of this module are
344343
# invoked often in a typical rails, both of which invoke the method
345344
# +matched_attribute_method+. The latter method iterates through an
@@ -458,12 +457,11 @@ def respond_to?(method, include_private_methods = false)
458457
end
459458
end
460459

461-
protected
462-
def attribute_method?(attr_name) #:nodoc:
460+
private
461+
def attribute_method?(attr_name)
463462
respond_to_without_attributes?(:attributes) && attributes.include?(attr_name)
464463
end
465464

466-
private
467465
# Returns a struct representing the matching attribute method.
468466
# The struct's attributes are prefix, base and suffix.
469467
def matched_attribute_method(method_name)

activemodel/lib/active_model/forbidden_attributes_protection.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ForbiddenAttributesError < StandardError
1515
end
1616

1717
module ForbiddenAttributesProtection # :nodoc:
18-
protected
18+
private
1919
def sanitize_for_mass_assignment(attributes)
2020
if attributes.respond_to?(:permitted?)
2121
raise ActiveModel::ForbiddenAttributesError if !attributes.permitted?

activemodel/lib/active_model/validations.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,14 +399,14 @@ def validate!(context = nil)
399399
# end
400400
alias :read_attribute_for_validation :send
401401

402-
protected
402+
private
403403

404-
def run_validations! #:nodoc:
404+
def run_validations!
405405
_run_validate_callbacks
406406
errors.empty?
407407
end
408408

409-
def raise_validation_error
409+
def raise_validation_error # :doc:
410410
raise(ValidationError.new(self))
411411
end
412412
end

activemodel/lib/active_model/validations/callbacks.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,10 @@ def after_validation(*args, &block)
104104
end
105105
end
106106

107-
protected
107+
private
108108

109109
# Overwrite run validations to include callbacks.
110-
def run_validations! #:nodoc:
110+
def run_validations!
111111
_run_validation_callbacks { super }
112112
end
113113
end

activemodel/lib/active_model/validations/numericality.rb

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,29 +61,29 @@ def validate_each(record, attr_name, value)
6161
end
6262
end
6363

64-
protected
64+
private
6565

66-
def is_number?(raw_value)
66+
def is_number?(raw_value) # :doc:
6767
!parse_raw_value_as_a_number(raw_value).nil?
6868
rescue ArgumentError, TypeError
6969
false
7070
end
7171

72-
def parse_raw_value_as_a_number(raw_value)
72+
def parse_raw_value_as_a_number(raw_value) # :doc:
7373
Kernel.Float(raw_value) if raw_value !~ /\A0[xX]/
7474
end
7575

76-
def is_integer?(raw_value)
76+
def is_integer?(raw_value) # :doc:
7777
/\A[+-]?\d+\z/ === raw_value.to_s
7878
end
7979

80-
def filtered_options(value)
80+
def filtered_options(value) # :doc:
8181
filtered = options.except(*RESERVED_OPTIONS)
8282
filtered[:value] = value
8383
filtered
8484
end
8585

86-
def allow_only_integer?(record)
86+
def allow_only_integer?(record) # :doc:
8787
case options[:only_integer]
8888
when Symbol
8989
record.send(options[:only_integer])
@@ -94,12 +94,10 @@ def allow_only_integer?(record)
9494
end
9595
end
9696

97-
private
98-
99-
def record_attribute_changed_in_place?(record, attr_name)
100-
record.respond_to?(:attribute_changed_in_place?) &&
101-
record.attribute_changed_in_place?(attr_name.to_s)
102-
end
97+
def record_attribute_changed_in_place?(record, attr_name)
98+
record.respond_to?(:attribute_changed_in_place?) &&
99+
record.attribute_changed_in_place?(attr_name.to_s)
100+
end
103101
end
104102

105103
module HelperMethods

activemodel/lib/active_model/validations/validates.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,15 +148,15 @@ def validates!(*attributes)
148148
validates(*(attributes << options))
149149
end
150150

151-
protected
151+
private
152152

153153
# When creating custom validators, it might be useful to be able to specify
154154
# additional default keys. This can be done by overwriting this method.
155-
def _validates_default_keys # :nodoc:
155+
def _validates_default_keys
156156
[:if, :unless, :on, :allow_blank, :allow_nil , :strict]
157157
end
158158

159-
def _parse_validates_options(options) # :nodoc:
159+
def _parse_validates_options(options)
160160
case options
161161
when TrueClass
162162
{}

0 commit comments

Comments
 (0)