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

Merge pull request #29261 from kamipo/dont_expose_methods_and_attrs_for_internal_usage

Don't expose methods and attrs for internal usage
This commit is contained in:
Matthew Draper 2017-05-31 04:26:52 +09:30 committed by GitHub
commit f495e0ff0b
7 changed files with 40 additions and 30 deletions

View file

@ -4,8 +4,6 @@ module ActiveRecord
module Associations
# Keeps track of table aliases for ActiveRecord::Associations::JoinDependency
class AliasTracker # :nodoc:
attr_reader :aliases
def self.create(connection, initial_table, type_caster)
aliases = Hash.new(0)
aliases[initial_table] = 1
@ -80,6 +78,11 @@ module ActiveRecord
end
end
# TODO Change this to private once we've dropped Ruby 2.2 support.
# Workaround for Ruby 2.2 "private attribute?" warning.
protected
attr_reader :aliases
private
def truncate(name)

View file

@ -51,11 +51,10 @@ module ActiveRecord
raise NotImplementedError
end
def options
reflection.options
end
private
def options
reflection.options
end
def associated_records_by_owner(preloader)
records = load_records do |record|

View file

@ -3,7 +3,7 @@ module ActiveRecord
class Preloader
class BelongsTo < SingularAssociation #:nodoc:
def association_key_name
reflection.options[:primary_key] || klass && klass.primary_key
options[:primary_key] || klass && klass.primary_key
end
def owner_key_name

View file

@ -65,7 +65,7 @@ module ActiveRecord
def reset_association(owners, association_name)
should_reset = (through_scope != through_reflection.klass.unscoped) ||
(reflection.options[:source_type] && through_reflection.collection?)
(options[:source_type] && through_reflection.collection?)
# Don't cache the association - we would only be caching a subset
if should_reset

View file

@ -287,6 +287,11 @@ module ActiveRecord
JoinKeys.new(join_pk(association_klass), join_fk)
end
protected
def actual_source_reflection # FIXME: this is a horrible name
self
end
private
def join_pk(_)
@ -583,12 +588,6 @@ module ActiveRecord
Array(options[:extend])
end
protected
def actual_source_reflection # FIXME: this is a horrible name
self
end
private
def calculate_constructable(macro, options)
@ -761,7 +760,6 @@ module ActiveRecord
# Holds all the metadata about a :through association as it was specified
# in the Active Record class.
class ThroughReflection < AbstractReflection #:nodoc:
attr_reader :delegate_reflection
delegate :foreign_key, :foreign_type, :association_foreign_key,
:active_record_primary_key, :type, :get_join_keys, to: :source_reflection
@ -987,19 +985,23 @@ module ActiveRecord
collect_join_reflections(seed + [self])
end
def collect_join_reflections(seed)
a = source_reflection.add_as_source seed
if options[:source_type]
through_reflection.add_as_polymorphic_through self, a
else
through_reflection.add_as_through a
end
end
private
# TODO Change this to private once we've dropped Ruby 2.2 support.
# Workaround for Ruby 2.2 "private attribute?" warning.
protected
attr_reader :delegate_reflection
def actual_source_reflection # FIXME: this is a horrible name
source_reflection.send(:actual_source_reflection)
source_reflection.actual_source_reflection
end
private
def collect_join_reflections(seed)
a = source_reflection.add_as_source seed
if options[:source_type]
through_reflection.add_as_polymorphic_through self, a
else
through_reflection.add_as_through a
end
end
def primary_key(klass)

View file

@ -1,8 +1,6 @@
module ActiveRecord
class PredicateBuilder
class AssociationQueryValue # :nodoc:
attr_reader :associated_table, :value
def initialize(associated_table, value)
@associated_table = associated_table
@value = value
@ -12,6 +10,11 @@ module ActiveRecord
[associated_table.association_foreign_key.to_s => ids]
end
# TODO Change this to private once we've dropped Ruby 2.2 support.
# Workaround for Ruby 2.2 "private attribute?" warning.
protected
attr_reader :associated_table, :value
private
def ids
case value

View file

@ -1,8 +1,6 @@
module ActiveRecord
class PredicateBuilder
class PolymorphicArrayValue # :nodoc:
attr_reader :associated_table, :values
def initialize(associated_table, values)
@associated_table = associated_table
@values = values
@ -17,6 +15,11 @@ module ActiveRecord
end
end
# TODO Change this to private once we've dropped Ruby 2.2 support.
# Workaround for Ruby 2.2 "private attribute?" warning.
protected
attr_reader :associated_table, :values
private
def type_to_ids_mapping
default_hash = Hash.new { |hsh, key| hsh[key] = [] }