diff options
author | Kevin Deisz <kevin.deisz@gmail.com> | 2018-05-31 21:15:51 -0400 |
---|---|---|
committer | Kevin Deisz <kevin.deisz@gmail.com> | 2018-05-31 21:15:51 -0400 |
commit | 6c7e6abfaad149da02dbec4e4f2bd62c5d68805f (patch) | |
tree | 35ed52dac9696d7eecb0bdeb63e9dfe69f61e19d /activerecord/lib/active_record | |
parent | ce337d1757fdd01e5f496f741e33275a7440b9ac (diff) | |
download | rails-6c7e6abfaad149da02dbec4e4f2bd62c5d68805f.tar.gz rails-6c7e6abfaad149da02dbec4e4f2bd62c5d68805f.tar.bz2 rails-6c7e6abfaad149da02dbec4e4f2bd62c5d68805f.zip |
Ensure reflection_class_for is private
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/reflection.rb | 51 |
1 files changed, 27 insertions, 24 deletions
diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb index c47e0dc03c..6d2f75a3ae 100644 --- a/activerecord/lib/active_record/reflection.rb +++ b/activerecord/lib/active_record/reflection.rb @@ -13,34 +13,37 @@ module ActiveRecord class_attribute :aggregate_reflections, instance_writer: false, default: {} end - def self.create(macro, name, scope, options, ar) - reflection = reflection_class_for(macro).new(name, scope, options, ar) - options[:through] ? ThroughReflection.new(reflection) : reflection - end + 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) - case macro - when :composed_of - AggregateReflection - when :has_many - HasManyReflection - when :has_one - HasOneReflection - when :belongs_to - BelongsToReflection - else - raise "Unsupported Macro: #{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 - 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 add_aggregate_reflection(ar, name, reflection) + ar.aggregate_reflections = ar.aggregate_reflections.merge(name.to_s => reflection) + end - def self.add_aggregate_reflection(ar, name, reflection) - ar.aggregate_reflections = ar.aggregate_reflections.merge(name.to_s => reflection) + private + def reflection_class_for(macro) + case macro + when :composed_of + AggregateReflection + when :has_many + HasManyReflection + when :has_one + HasOneReflection + when :belongs_to + BelongsToReflection + else + raise "Unsupported Macro: #{macro}" + end + end end # \Reflection enables the ability to examine the associations and aggregations of |