Module: ModelManage::Mongoid::ClassMethods

Defined in:
lib/model_manage/form.rb,
lib/model_manage/mongoid_rails_erd.rb,
lib/model_manage/mongoid.rb

Instance Method Summary collapse

Instance Method Details

#base_classObject



46
47
48
# File 'lib/model_manage/mongoid_rails_erd.rb', line 46

def base_class
  class_of_active_record_descendant(self)
end

#belongs_to(name, options = {}) ⇒ Object



30
31
32
33
34
# File 'lib/model_manage/mongoid.rb', line 30

def belongs_to(name, options = {})
  super
  relation_form_set name, options
  forms.delete("#{name}_id")
end

#class_of_active_record_descendant(klass) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/model_manage/mongoid_rails_erd.rb', line 50

def class_of_active_record_descendant(klass)
  if not Rails.models.member? klass.superclass
    klass
  else
    class_of_active_record_descendant(klass.superclass)
  end
end

#column_for_attribute(attribute_name) ⇒ Object



4
5
6
# File 'lib/model_manage/form.rb', line 4

def column_for_attribute(attribute_name)
  self.class.forms[attribute_name.to_s]
end

#columnsObject



29
30
31
# File 'lib/model_manage/mongoid_rails_erd.rb', line 29

def columns
  forms.values
end

#columns_hashObject



33
34
35
# File 'lib/model_manage/mongoid_rails_erd.rb', line 33

def columns_hash
  forms
end

#content_columnsObject



8
9
10
# File 'lib/model_manage/form.rb', line 8

def content_columns
  forms.values
end

#descends_from_active_record?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/model_manage/mongoid_rails_erd.rb', line 37

def descends_from_active_record?
  Rails.child_models.member? self
end

#embedded_in(name, options = {}) ⇒ Object



52
53
54
55
56
# File 'lib/model_manage/mongoid.rb', line 52

def embedded_in(name, options = {})
  super
  relation_form_set name, options
  forms.delete("#{name}_id")
end

#embeds_many(name, options = {}) ⇒ Object



57
58
59
60
61
# File 'lib/model_manage/mongoid.rb', line 57

def embeds_many(name, options = {})
  super
  relation_form_set name, options
  forms.delete("#{name.to_s.singularize}_ids")
end

#has_and_belongs_to_many(name, options = {}) ⇒ Object



63
64
65
66
67
# File 'lib/model_manage/mongoid.rb', line 63

def has_and_belongs_to_many(name, options = {})
  super
  relation_form_set name, options
  forms.delete("#{name.to_s.singularize}_ids")
end

#has_many(name, options = {}) ⇒ Object



41
42
43
44
45
# File 'lib/model_manage/mongoid.rb', line 41

def has_many(name, options = {})
  super
  relation_form_set name, options
  forms.delete("#{name.to_s.singularize}_ids")
end

#inheritance_columnObject



25
26
27
# File 'lib/model_manage/mongoid_rails_erd.rb', line 25

def inheritance_column
  '_type'
end

#key(*keys) ⇒ Object



26
27
28
29
# File 'lib/model_manage/mongoid.rb', line 26

def key(* keys)
  const_set :KEYS, keys.map(&:to_s)
  super
end

#referenced_in(name, options = {}) ⇒ Object



35
36
37
38
39
# File 'lib/model_manage/mongoid.rb', line 35

def referenced_in(name, options = {})
  super
  relation_form_set name, options
  forms.delete("#{name}_id")
end

#references_and_referenced_in_many(name, options = {}) ⇒ Object



68
69
70
71
72
# File 'lib/model_manage/mongoid.rb', line 68

def references_and_referenced_in_many(name, options = {})
  super
  relation_form_set name, options
  forms.delete("#{name.to_s.singularize}_ids")
end

#references_many(name, options = {}) ⇒ Object



46
47
48
49
50
# File 'lib/model_manage/mongoid.rb', line 46

def references_many(name, options = {})
  super
  relation_form_set name, options
  forms.delete("#{name.to_s.singularize}_ids")
end

#reflect_on_all_associations(macro = nil) ⇒ Object



41
42
43
44
# File 'lib/model_manage/mongoid_rails_erd.rb', line 41

def reflect_on_all_associations(macro = nil)
  association_reflections = relations.values
  macro ? relations.select { |reflection| reflection.macro == macro } : association_reflections
end

#reflectionsObject



12
13
14
# File 'lib/model_manage/form.rb', line 12

def reflections
  relations
end