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

Ensure reflection_class_for is private

This commit is contained in:
Kevin Deisz 2018-05-31 21:15:51 -04:00
parent ce337d1757
commit 6c7e6abfaa
No known key found for this signature in database
GPG key ID: D78C2D8FB232C59C
2 changed files with 41 additions and 37 deletions

View file

@ -13,12 +13,24 @@ module ActiveRecord
class_attribute :aggregate_reflections, instance_writer: false, default: {}
end
def self.create(macro, name, scope, options, ar)
class << self
def create(macro, name, scope, options, ar)
reflection = reflection_class_for(macro).new(name, scope, options, ar)
options[:through] ? ThroughReflection.new(reflection) : reflection
end
def self.reflection_class_for(macro)
def add_reflection(ar, name, reflection)
ar.clear_reflections_cache
name = name.to_s
ar._reflections = ar._reflections.except(name).merge!(name => reflection)
end
def add_aggregate_reflection(ar, name, reflection)
ar.aggregate_reflections = ar.aggregate_reflections.merge(name.to_s => reflection)
end
private
def reflection_class_for(macro)
case macro
when :composed_of
AggregateReflection
@ -32,15 +44,6 @@ module ActiveRecord
raise "Unsupported Macro: #{macro}"
end
end
def self.add_reflection(ar, name, reflection)
ar.clear_reflections_cache
name = name.to_s
ar._reflections = ar._reflections.except(name).merge!(name => reflection)
end
def self.add_aggregate_reflection(ar, name, reflection)
ar.aggregate_reflections = ar.aggregate_reflections.merge(name.to_s => reflection)
end
# \Reflection enables the ability to examine the associations and aggregations of

View file

@ -18,7 +18,12 @@ module ActiveStorage
end
end
module ReflectionExtension
module ReflectionExtension # :nodoc:
def add_attachment_reflection(ar, name, reflection)
ar.attachment_reflections.merge!(name.to_s => reflection)
end
private
def reflection_class_for(macro)
case macro
when :has_one_attached
@ -29,10 +34,6 @@ module ActiveStorage
super
end
end
def add_attachment_reflection(ar, name, reflection)
ar.attachment_reflections.merge!(name.to_s => reflection)
end
end
module ActiveRecordExtensions