module ActiveModularity::Modulize::ClassMethods
Public Instance Methods
descends_from_active_record?()
click to toggle source
Calls superclass method
# File lib/active_modularity/modulize.rb, line 39 def descends_from_active_record? if @@force_sti_base && ActiveRecord::Base != superclass && !self.abstract_class? && superclass.descends_from_active_record? && superclass.name == name.demodulize && columns_hash.include?(inheritance_column) return true end super end
find_sti_class(type_name)
click to toggle source
fix inner module single table inheritance
Calls superclass method
# File lib/active_modularity/modulize.rb, line 26 def find_sti_class(type_name) module_name = self.name.deconstantize if type_name && module_name.present? type_name = "#{module_name}::#{type_name}" end super end
force_sti_base!()
click to toggle source
fix inner module sti base class
# File lib/active_modularity/modulize.rb, line 35 def force_sti_base! @@force_sti_base = true end
inherited_with_modularity(subclass)
click to toggle source
# File lib/active_modularity/modulize.rb, line 12 def inherited_with_modularity(subclass) inherited_without_modularity(subclass).tap do subclass.modulize! end end
modulize!()
click to toggle source
# File lib/active_modularity/modulize.rb, line 18 def modulize! return if self == ActiveRecord::Base modulize_reflections! self.store_full_sti_class = false force_sti_base! end
modulize_reflection(reflection)
click to toggle source
# File lib/active_modularity/modulize.rb, line 56 def modulize_reflection(reflection) return reflection if reflection.active_record != superclass return reflection unless reflection.kind_of?(ActiveRecord::Reflection::AssociationReflection) modulized_reflection = reflection.dup modulized_reflection.instance_variable_set(:@active_record, self) modulized_reflection.instance_variable_set(:@class_name, nil) modulized_reflection.instance_variable_set(:@klass, nil) modulized_reflection.instance_variable_set(:@foreign_key, reflection.foreign_key) modulized_reflection end
modulize_reflections!()
click to toggle source
fix inner module reflections
# File lib/active_modularity/modulize.rb, line 52 def modulize_reflections! self.reflections = Hash[superclass.reflections.map{|k,v| [k, modulize_reflection(v)]}] end