未验证 提交 6c7e6abf 编写于 作者: K Kevin Deisz

Ensure reflection_class_for is private

上级 ce337d17
......@@ -13,34 +13,37 @@ module Reflection # :nodoc:
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
......
......@@ -18,21 +18,22 @@ def macro
end
end
module ReflectionExtension
def reflection_class_for(macro)
case macro
when :has_one_attached
HasOneAttachedReflection
when :has_many_attached
HasManyAttachedReflection
else
super
end
end
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
HasOneAttachedReflection
when :has_many_attached
HasManyAttachedReflection
else
super
end
end
end
module ActiveRecordExtensions
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册