Class: Traits::Model

Inherits:
Base
  • Object
show all
Includes:
EssayShortcuts, I18n, Inheritance, Naming, Polymorphism, Querying
Defined in:
lib/traits/model.rb,
lib/traits/model.rb,
lib/traits/model/i18n.rb,
lib/traits/model/naming.rb,
lib/traits/model/querying.rb,
lib/traits/model/inheritance.rb,
lib/traits/model/polymorphism.rb,
lib/traits/model/essay_shortcuts.rb

Defined Under Namespace

Modules: EssayShortcuts, I18n, Inheritance, Naming, Polymorphism, Querying

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from I18n

#i18n_path

Methods included from EssayShortcuts

#features

Methods included from Querying

#arel, #connection, #primary_key_attribute, #primary_key_name, #quoted_table_name, #table_name

Methods included from Polymorphism

#polymorphic_type

Methods included from Inheritance

#inheritance_attribute, #inheritance_attribute_name, #inheritance_base, #inheritance_base?, #inheritance_chain, #inheritance_derived?, #uses_inheritance?

Methods included from Naming

#class_name, #lookup_name, #name, #plural_name, #resource_name

Constructor Details

#initialize(model_class) ⇒ Model

Returns a new instance of Model.



30
31
32
# File 'lib/traits/model.rb', line 30

def initialize(model_class)
  @model_class = model_class
end

Instance Attribute Details

#model_classObject (readonly) Also known as: active_record, klass

Returns the value of attribute model_class.



25
26
27
# File 'lib/traits/model.rb', line 25

def model_class
  @model_class
end

Instance Method Details

#associationsObject



38
39
40
# File 'lib/traits/model.rb', line 38

def associations
  @associations ||= inspect_associations
end

#attributesObject



34
35
36
# File 'lib/traits/model.rb', line 34

def attributes
  @attributes ||= inspect_attributes
end

#descendantsObject



53
54
55
56
# File 'lib/traits/model.rb', line 53

def descendants
  Traits.load_active_record_descendants!
  active_record.descendants
end

#to_hashObject



46
47
48
49
50
51
# File 'lib/traits/model.rb', line 46

def to_hash
  super.merge!(
    attributes:   attributes.to_hash,
    associations: associations.to_hash
  )
end

#to_sObject



42
43
44
# File 'lib/traits/model.rb', line 42

def to_s
  class_name
end