Class: Traits::Model

Inherits:
Base
  • Object
show all
Includes:
EssayShortcuts, Naming, Polymorphism, Querying, STI
Defined in:
lib/traits/model.rb,
lib/traits/model.rb,
lib/traits/concerns/model/sti.rb,
lib/traits/concerns/model/naming.rb,
lib/traits/concerns/model/querying.rb,
lib/traits/concerns/model/polymorphism.rb,
lib/traits/concerns/model/essay_shortcuts.rb

Defined Under Namespace

Modules: EssayShortcuts, Naming, Polymorphism, Querying, STI

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from EssayShortcuts

#features

Methods included from Querying

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

Methods included from Polymorphism

#polymorphic_type

Methods included from STI

#sti_attribute_name, #sti_base?, #sti_chain, #sti_derived?, #uses_sti?

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.



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

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.



20
21
22
# File 'lib/traits/model.rb', line 20

def model_class
  @model_class
end

Instance Method Details

#associationsObject



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

def associations
  @associations ||= inspect_associations
end

#attributesObject



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

def attributes
  @attributes ||= inspect_attributes
end

#to_hashObject



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

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

#to_sObject



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

def to_s
  class_name
end