Sha256: 24870fd878d7b0eb254be1775e2219bf91c0a39977be2f3f2107c3e9956f926d
Contents?: true
Size: 1.3 KB
Versions: 8
Compression:
Stored size: 1.3 KB
Contents
module ActiveRecord module Mlang module Text def self.included(base) base.extend ClassMethods base.belongs_to :lang base.set_parent_reflection end module ClassMethods def parent_class_name(parent_class_name=nil) if parent_class_name self.parent_class_name = parent_class_name else @parent_class_name || self.name.gsub(/Text$/,'') end end def parent_class_name=(parent_class_name) @parent_class_name = parent_class_name.to_s set_parent_reflection self end def parent_fkey(parent_fkey=nil) if parent_fkey self.parent_fkey = parent_fkey else @parent_fkey || :parent_id end end def parent_fkey=(parent_fkey) @parent_fkey = parent_fkey set_parent_reflection self end def set_parent_reflection belongs_to :parent, class_name: self.parent_class_name, foreign_key: self.parent_fkey if p = self.parent_ && p.respond_to?(:set_text_reflection) p.set_text_reflection end end def parent_ # parent is used self.parent_class_name.safe_constantize end end end end end
Version data entries
8 entries across 8 versions & 1 rubygems