Class: Traits::Attribute
- Includes:
- EssayShortcuts, Inheritance, Key, Naming, Polymorphism, Querying, Type
- Defined in:
- lib/traits/attribute.rb,
lib/traits/attribute.rb,
lib/traits/attribute/key.rb,
lib/traits/attribute/type.rb,
lib/traits/attribute/naming.rb,
lib/traits/attribute/querying.rb,
lib/traits/attribute/inheritance.rb,
lib/traits/attribute/polymorphism.rb,
lib/traits/attribute/essay_shortcuts.rb
Defined Under Namespace
Modules: EssayShortcuts, Inheritance, Key, Naming, Polymorphism, Querying, Type
Instance Attribute Summary collapse
-
#active_record ⇒ Object
readonly
Returns the value of attribute active_record.
-
#column_definition ⇒ Object
readonly
Returns the value of attribute column_definition.
Instance Method Summary collapse
- #association ⇒ Object
-
#initialize(active_record, column_definition) ⇒ Attribute
constructor
A new instance of Attribute.
- #inspect ⇒ Object
- #model ⇒ Object
- #null? ⇒ Boolean
-
#regular? ⇒ Boolean
TODO Remove this.
- #to_s ⇒ Object
- #validators ⇒ Object
- #value_from(model_instance) ⇒ Object
Methods included from EssayShortcuts
Methods included from Inheritance
Methods included from Querying
Methods included from Polymorphism
#polymorphic_key?, #polymorphic_type?, #to_hash
Methods included from Type
#active_record_timestamp?, #big?, #binary?, #datetime?, #decimal?, #float?, #integer?, #number?, #real?, #string?, #text?, #to_hash, #type
Methods included from Naming
Methods included from Key
#foreign_key?, #key?, #primary_key?, #to_hash
Methods inherited from Base
Constructor Details
#initialize(active_record, column_definition) ⇒ Attribute
Returns a new instance of Attribute.
29 30 31 32 |
# File 'lib/traits/attribute.rb', line 29 def initialize(active_record, column_definition) @active_record = active_record @column_definition = column_definition end |
Instance Attribute Details
#active_record ⇒ Object (readonly)
Returns the value of attribute active_record.
27 28 29 |
# File 'lib/traits/attribute.rb', line 27 def active_record @active_record end |
#column_definition ⇒ Object (readonly)
Returns the value of attribute column_definition.
27 28 29 |
# File 'lib/traits/attribute.rb', line 27 def column_definition @column_definition end |
Instance Method Details
#association ⇒ Object
59 60 61 |
# File 'lib/traits/attribute.rb', line 59 def association model.associations.first_where(from_key_name: name) end |
#inspect ⇒ Object
51 52 53 |
# File 'lib/traits/attribute.rb', line 51 def inspect "#{model}##{name}" end |
#model ⇒ Object
34 35 36 |
# File 'lib/traits/attribute.rb', line 34 def model active_record.traits end |
#null? ⇒ Boolean
63 64 65 |
# File 'lib/traits/attribute.rb', line 63 def null? column_definition.null end |
#regular? ⇒ Boolean
TODO Remove this
39 40 41 |
# File 'lib/traits/attribute.rb', line 39 def regular? !(key? || inheritance_type? || polymorphic_type? || ) end |
#to_s ⇒ Object
55 56 57 |
# File 'lib/traits/attribute.rb', line 55 def to_s name end |
#validators ⇒ Object
43 44 45 |
# File 'lib/traits/attribute.rb', line 43 def validators active_record.validators_on(name) end |
#value_from(model_instance) ⇒ Object
47 48 49 |
# File 'lib/traits/attribute.rb', line 47 def value_from(model_instance) model_instance.send(name) end |