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
- #base_class ⇒ Object
- #belongs_to(name, options = {}) ⇒ Object
- #class_of_active_record_descendant(klass) ⇒ Object
- #column_for_attribute(attribute_name) ⇒ Object
- #columns ⇒ Object
- #columns_hash ⇒ Object
- #content_columns ⇒ Object
- #descends_from_active_record? ⇒ Boolean
- #embedded_in(name, options = {}) ⇒ Object
- #embeds_many(name, options = {}) ⇒ Object
- #has_and_belongs_to_many(name, options = {}) ⇒ Object
- #has_many(name, options = {}) ⇒ Object
- #inheritance_column ⇒ Object
- #key(*keys) ⇒ Object
- #referenced_in(name, options = {}) ⇒ Object
- #references_and_referenced_in_many(name, options = {}) ⇒ Object
- #references_many(name, options = {}) ⇒ Object
- #reflect_on_all_associations(macro = nil) ⇒ Object
- #reflections ⇒ Object
Instance Method Details
#base_class ⇒ Object
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, = {}) super relation_form_set name, 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 |
#columns ⇒ Object
29 30 31 |
# File 'lib/model_manage/mongoid_rails_erd.rb', line 29 def columns forms.values end |
#columns_hash ⇒ Object
33 34 35 |
# File 'lib/model_manage/mongoid_rails_erd.rb', line 33 def columns_hash forms end |
#content_columns ⇒ Object
8 9 10 |
# File 'lib/model_manage/form.rb', line 8 def content_columns forms.values end |
#descends_from_active_record? ⇒ 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 (name, = {}) super relation_form_set name, forms.delete("#{name}_id") end |
#embeds_many(name, options = {}) ⇒ Object
57 58 59 60 61 |
# File 'lib/model_manage/mongoid.rb', line 57 def (name, = {}) super relation_form_set name, 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, = {}) super relation_form_set name, 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, = {}) super relation_form_set name, forms.delete("#{name.to_s.singularize}_ids") end |
#inheritance_column ⇒ Object
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, = {}) super relation_form_set name, 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, = {}) super relation_form_set name, 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, = {}) super relation_form_set name, 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 |
#reflections ⇒ Object
12 13 14 |
# File 'lib/model_manage/form.rb', line 12 def reflections relations end |