Module: ActiveRecord::Mlang::ClassMethods

Defined in:
lib/active_record/mlang.rb

Instance Method Summary collapse

Instance Method Details

#has_many_fkeyObject



41
42
43
44
45
46
47
# File 'lib/active_record/mlang.rb', line 41

def has_many_fkey
  if self.text
    self.text.parent_fkey
  else
    :parent_id
  end
end

#has_text?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/active_record/mlang.rb', line 29

def has_text?
  !!self.text
end

#set_text_reflectionObject



49
50
51
# File 'lib/active_record/mlang.rb', line 49

def set_text_reflection
  has_many :texts, class_name: self.text_class_name, foreign_key: self.has_many_fkey
end

#textObject



25
26
27
# File 'lib/active_record/mlang.rb', line 25

def text
  self.text_class_name.safe_constantize
end

#text_attrs(*args) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/active_record/mlang.rb', line 33

def text_attrs(*args)
  args.each do |arg|
    define_method(arg.to_sym){
      self.text.__send__(arg)
    }
  end
end

#text_class_name(text_class_name = nil) ⇒ Object



13
14
15
16
17
18
# File 'lib/active_record/mlang.rb', line 13

def text_class_name(text_class_name=nil)
  if text_class_name
    self.text_class_name = text_class_name
  end
  @text_class_name || (self.name + "Text")
end

#text_class_name=(text_class_name) ⇒ Object



20
21
22
23
# File 'lib/active_record/mlang.rb', line 20

def text_class_name=(text_class_name)
  @text_class_name = text_class_name
  self.set_text_reflection
end