Module: DuckRecord::Reflection
Overview
Active Record Reflection
Defined Under Namespace
Modules: ClassMethods Classes: AbstractReflection, AssociationReflection, BelongsToReflection, EmbedsAssociationReflection, EmbedsManyReflection, EmbedsOneReflection, HasManyReflection, HasOneReflection, MacroReflection
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.add_reflection(ar, name, reflection) ⇒ Object
35 36 37 38 |
# File 'lib/duck_record/reflection.rb', line 35 def self.add_reflection(ar, name, reflection) ar.clear_reflections_cache ar._reflections = ar._reflections.merge(name.to_s => reflection) end |
.create(macro, name, scope, options, ar) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/duck_record/reflection.rb', line 15 def self.create(macro, name, scope, , ar) klass = \ case macro when :embeds_many EmbedsManyReflection when :embeds_one EmbedsOneReflection when :belongs_to BelongsToReflection when :has_many HasManyReflection when :has_one HasOneReflection else raise "Unsupported Macro: #{macro}" end klass.new(name, scope, , ar) end |
Instance Method Details
#has_reflection?(reflection_name) ⇒ Boolean
40 41 42 |
# File 'lib/duck_record/reflection.rb', line 40 def has_reflection?(reflection_name) _reflections.keys.include?(reflection_name.to_s) end |