Skip to content

Commit 5b14129

Browse files
committed
Privatize unneededly protected methods in Active Record
1 parent 6c5bbb4 commit 5b14129

File tree

26 files changed

+145
-158
lines changed

26 files changed

+145
-158
lines changed

activerecord/lib/active_record/associations/collection_proxy.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,20 +1126,18 @@ def reset
11261126
self
11271127
end
11281128

1129-
protected
1129+
private
11301130

1131-
def find_nth_with_limit(index, limit)
1131+
def find_nth_with_limit(index, limit) # :doc:
11321132
load_target if find_from_target?
11331133
super
11341134
end
11351135

1136-
def find_nth_from_last(index)
1136+
def find_nth_from_last(index) # :doc:
11371137
load_target if find_from_target?
11381138
super
11391139
end
11401140

1141-
private
1142-
11431141
def null_scope?
11441142
@association.null_scope?
11451143
end

activerecord/lib/active_record/associations/through_association.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ module Associations
44
module ThroughAssociation #:nodoc:
55
delegate :source_reflection, :through_reflection, to: :reflection
66

7-
protected
7+
private
88

99
# We merge in these scopes for two reasons:
1010
#
1111
# 1. To get the default_scope conditions for any of the other reflections in the chain
1212
# 2. To get the type conditions for any STI models in the chain
13-
def target_scope
13+
def target_scope # :doc:
1414
scope = super
1515
reflection.chain.drop(1).each do |reflection|
1616
relation = reflection.klass.all
@@ -21,8 +21,6 @@ def target_scope
2121
scope
2222
end
2323

24-
private
25-
2624
# Construct attributes for :through pointing to owner and associate. This is used by the
2725
# methods which create and delete records on the association.
2826
#

activerecord/lib/active_record/attribute.rb

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -135,25 +135,26 @@ def encode_with(coder)
135135
attr_reader :original_attribute
136136
alias_method :assigned?, :original_attribute
137137

138-
def initialize_dup(other)
138+
def original_value_for_database # :doc:
139+
if assigned?
140+
original_attribute.original_value_for_database
141+
else
142+
_original_value_for_database
143+
end
144+
end
145+
146+
private
147+
def initialize_dup(other) # :doc:
139148
if defined?(@value) && @value.duplicable?
140149
@value = @value.dup
141150
end
142151
end
143152

144-
def changed_from_assignment?
153+
def changed_from_assignment? # :doc:
145154
assigned? && type.changed?(original_value, value, value_before_type_cast)
146155
end
147156

148-
def original_value_for_database
149-
if assigned?
150-
original_attribute.original_value_for_database
151-
else
152-
_original_value_for_database
153-
end
154-
end
155-
156-
def _original_value_for_database
157+
def _original_value_for_database # :doc:
157158
type.serialize(original_value)
158159
end
159160

activerecord/lib/active_record/attribute_methods/primary_key.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ def id_in_database
5050
attribute_in_database(self.class.primary_key)
5151
end
5252

53-
protected
53+
private
5454

55-
def attribute_method?(attr_name)
55+
def attribute_method?(attr_name) # :doc:
5656
attr_name == "id" || super
5757
end
5858

activerecord/lib/active_record/attribute_methods/read.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module Read
44
extend ActiveSupport::Concern
55

66
module ClassMethods
7-
protected
7+
private
88

99
# We want to generate the methods via module_eval rather than
1010
# define_method, because define_method is slower on dispatch.
@@ -24,7 +24,7 @@ module ClassMethods
2424
# to allocate an object on each call to the attribute method.
2525
# Making it frozen means that it doesn't get duped when used to
2626
# key the @attributes in read_attribute.
27-
def define_method_attribute(name)
27+
def define_method_attribute(name) # :doc:
2828
safe_name = name.unpack("h*".freeze).first
2929
temp_method = "__temp__#{safe_name}"
3030

activerecord/lib/active_record/attribute_methods/write.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ module Write
88
end
99

1010
module ClassMethods
11-
protected
11+
private
1212

13-
def define_method_attribute=(name)
13+
def define_method_attribute=(name) # :doc:
1414
safe_name = name.unpack("h*".freeze).first
1515
ActiveRecord::AttributeMethods::AttrNames.set_name_cache safe_name, name
1616

activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -360,34 +360,34 @@ def join_to_update(update, select, key) # :nodoc:
360360
end
361361
alias join_to_delete join_to_update
362362

363-
protected
363+
private
364364

365365
# Returns a subquery for the given key using the join information.
366-
def subquery_for(key, select)
366+
def subquery_for(key, select) # :doc:
367367
subselect = select.clone
368368
subselect.projections = [key]
369369
subselect
370370
end
371371

372372
# Returns an ActiveRecord::Result instance.
373-
def select(sql, name = nil, binds = [])
373+
def select(sql, name = nil, binds = []) # :doc:
374374
exec_query(sql, name, binds, prepare: false)
375375
end
376376

377-
def select_prepared(sql, name = nil, binds = [])
377+
def select_prepared(sql, name = nil, binds = []) # :doc:
378378
exec_query(sql, name, binds, prepare: true)
379379
end
380380

381-
def sql_for_insert(sql, pk, id_value, sequence_name, binds)
381+
def sql_for_insert(sql, pk, id_value, sequence_name, binds) # :doc:
382382
[sql, binds]
383383
end
384384

385-
def last_inserted_id(result)
385+
def last_inserted_id(result) # :doc:
386386
row = result.rows.first
387387
row && row.first
388388
end
389389

390-
def binds_from_relation(relation, binds)
390+
def binds_from_relation(relation, binds) # :doc:
391391
if relation.is_a?(Relation) && binds.empty?
392392
relation, binds = relation.arel, relation.bound_attributes
393393
end

activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,9 +1169,9 @@ def change_column_comment(table_name, column_name, comment) #:nodoc:
11691169
raise NotImplementedError, "#{self.class} does not support changing column comments"
11701170
end
11711171

1172-
protected
1172+
private
11731173

1174-
def add_index_sort_order(quoted_columns, **options)
1174+
def add_index_sort_order(quoted_columns, **options) # :doc:
11751175
if order = options[:order]
11761176
case order
11771177
when Hash
@@ -1186,22 +1186,22 @@ def add_index_sort_order(quoted_columns, **options)
11861186
end
11871187

11881188
# Overridden by the MySQL adapter for supporting index lengths
1189-
def add_options_for_index_columns(quoted_columns, **options)
1189+
def add_options_for_index_columns(quoted_columns, **options) # :doc:
11901190
if supports_index_sort_order?
11911191
quoted_columns = add_index_sort_order(quoted_columns, options)
11921192
end
11931193

11941194
quoted_columns
11951195
end
11961196

1197-
def quoted_columns_for_index(column_names, **options)
1197+
def quoted_columns_for_index(column_names, **options) # :doc:
11981198
return [column_names] if column_names.is_a?(String)
11991199

12001200
quoted_columns = Hash[column_names.map { |name| [name.to_sym, quote_column_name(name).dup] }]
12011201
add_options_for_index_columns(quoted_columns, options).values
12021202
end
12031203

1204-
def index_name_for_remove(table_name, options = {})
1204+
def index_name_for_remove(table_name, options = {}) # :doc:
12051205
return options[:name] if can_remove_index_by_name?(options)
12061206

12071207
checks = []
@@ -1231,7 +1231,7 @@ def index_name_for_remove(table_name, options = {})
12311231
end
12321232
end
12331233

1234-
def rename_table_indexes(table_name, new_name)
1234+
def rename_table_indexes(table_name, new_name) # :doc:
12351235
indexes(new_name).each do |index|
12361236
generated_index_name = index_name(table_name, column: index.columns)
12371237
if generated_index_name == index.name
@@ -1240,7 +1240,7 @@ def rename_table_indexes(table_name, new_name)
12401240
end
12411241
end
12421242

1243-
def rename_column_indexes(table_name, column_name, new_column_name)
1243+
def rename_column_indexes(table_name, column_name, new_column_name) # :doc:
12441244
column_name, new_column_name = column_name.to_s, new_column_name.to_s
12451245
indexes(table_name).each do |index|
12461246
next unless index.columns.include?(new_column_name)
@@ -1253,7 +1253,6 @@ def rename_column_indexes(table_name, column_name, new_column_name)
12531253
end
12541254
end
12551255

1256-
private
12571256
def create_table_definition(*args)
12581257
TableDefinition.new(*args)
12591258
end

activerecord/lib/active_record/connection_adapters/abstract_adapter.rb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -499,9 +499,9 @@ def combine_bind_parameters(
499499
result
500500
end
501501

502-
protected
502+
private
503503

504-
def initialize_type_map(m) # :nodoc:
504+
def initialize_type_map(m)
505505
register_class_with_limit m, %r(boolean)i, Type::Boolean
506506
register_class_with_limit m, %r(char)i, Type::String
507507
register_class_with_limit m, %r(binary)i, Type::Binary
@@ -532,37 +532,37 @@ def initialize_type_map(m) # :nodoc:
532532
end
533533
end
534534

535-
def reload_type_map # :nodoc:
535+
def reload_type_map
536536
type_map.clear
537537
initialize_type_map(type_map)
538538
end
539539

540-
def register_class_with_limit(mapping, key, klass) # :nodoc:
540+
def register_class_with_limit(mapping, key, klass)
541541
mapping.register_type(key) do |*args|
542542
limit = extract_limit(args.last)
543543
klass.new(limit: limit)
544544
end
545545
end
546546

547-
def register_class_with_precision(mapping, key, klass) # :nodoc:
547+
def register_class_with_precision(mapping, key, klass)
548548
mapping.register_type(key) do |*args|
549549
precision = extract_precision(args.last)
550550
klass.new(precision: precision)
551551
end
552552
end
553553

554-
def extract_scale(sql_type) # :nodoc:
554+
def extract_scale(sql_type)
555555
case sql_type
556556
when /\((\d+)\)/ then 0
557557
when /\((\d+)(,(\d+))\)/ then $3.to_i
558558
end
559559
end
560560

561-
def extract_precision(sql_type) # :nodoc:
561+
def extract_precision(sql_type)
562562
$1.to_i if sql_type =~ /\((\d+)(,\d+)?\)/
563563
end
564564

565-
def extract_limit(sql_type) # :nodoc:
565+
def extract_limit(sql_type)
566566
case sql_type
567567
when /^bigint/i
568568
8
@@ -571,7 +571,7 @@ def extract_limit(sql_type) # :nodoc:
571571
end
572572
end
573573

574-
def translate_exception_class(e, sql)
574+
def translate_exception_class(e, sql) # :doc:
575575
begin
576576
message = "#{e.class.name}: #{e.message}: #{sql}"
577577
rescue Encoding::CompatibilityError
@@ -583,7 +583,7 @@ def translate_exception_class(e, sql)
583583
exception
584584
end
585585

586-
def log(sql, name = "SQL", binds = [], type_casted_binds = [], statement_name = nil)
586+
def log(sql, name = "SQL", binds = [], type_casted_binds = [], statement_name = nil) # :doc:
587587
@instrumenter.instrument(
588588
"sql.active_record",
589589
sql: sql,
@@ -596,7 +596,7 @@ def log(sql, name = "SQL", binds = [], type_casted_binds = [], statement_name =
596596
raise translate_exception_class(e, sql)
597597
end
598598

599-
def translate_exception(exception, message)
599+
def translate_exception(exception, message) # :doc:
600600
# override in derived class
601601
case exception
602602
when RuntimeError
@@ -606,11 +606,11 @@ def translate_exception(exception, message)
606606
end
607607
end
608608

609-
def without_prepared_statement?(binds)
609+
def without_prepared_statement?(binds) # :doc:
610610
!prepared_statements || binds.empty?
611611
end
612612

613-
def column_for(table_name, column_name) # :nodoc:
613+
def column_for(table_name, column_name)
614614
column_name = column_name.to_s
615615
columns(table_name).detect { |c| c.name == column_name } ||
616616
raise(ActiveRecordError, "No such column: #{table_name}.#{column_name}")

0 commit comments

Comments
 (0)