Class: Uuids::Base::BelongsTo
- Inherits:
-
Struct
- Object
- Struct
- Uuids::Base::BelongsTo
- Defined in:
- lib/uuids/base/belongs_to.rb
Overview
Adds getter and setter for the model attribute referred by uuid.
Instance Attribute Summary collapse
-
#class_name ⇒ String
readonly
The name of the #klass constant.
-
#klass ⇒ ActiveRecord::Base
The model to add the attribute to.
-
#model ⇒ ActiveRecord::Base
The model to be referred by uuid.
-
#model_name ⇒ String
readonly
The name of the #klass db table column to store reference to the attribute by uuid.
-
#name ⇒ String, Symbol
The name of the attribute to be added.
Class Method Summary collapse
-
.add(klass, name, model) ⇒ Object
Constructs the object and adds the attribute.
Instance Method Summary collapse
-
#add ⇒ Object
Adds the attribute’s getter and setter.
-
#column_name ⇒ String
The name of the #klass db table column to store reference to the attribute by uuid.
Instance Attribute Details
#class_name ⇒ String (readonly)
The name of the #klass constant.
33 34 35 |
# File 'lib/uuids/base/belongs_to.rb', line 33 def class_name @class_name ||= klass.name end |
#klass ⇒ ActiveRecord::Base
The model to add the attribute to.
12 13 14 |
# File 'lib/uuids/base/belongs_to.rb', line 12 def klass @klass end |
#model ⇒ ActiveRecord::Base
The model to be referred by uuid.
12 13 14 |
# File 'lib/uuids/base/belongs_to.rb', line 12 def model @model end |
#model_name ⇒ String (readonly)
The name of the #klass db table column to store reference to the
attribute by uuid.
41 42 43 |
# File 'lib/uuids/base/belongs_to.rb', line 41 def model_name @model_name ||= model.name end |
#name ⇒ String, Symbol
The name of the attribute to be added.
12 13 14 |
# File 'lib/uuids/base/belongs_to.rb', line 12 def name @name end |
Class Method Details
.add(klass, name, model) ⇒ Object
Constructs the object and adds the attribute.
63 64 65 |
# File 'lib/uuids/base/belongs_to.rb', line 63 def self.add(klass, name, model) new(klass, name, model).add end |
Instance Method Details
#add ⇒ Object
Adds the attribute’s getter and setter.
73 74 75 76 77 78 |
# File 'lib/uuids/base/belongs_to.rb', line 73 def add check_model check_column add_getter add_setter end |
#column_name ⇒ String
The name of the #klass db table column to store reference to the
attribute by uuid.
50 51 52 |
# File 'lib/uuids/base/belongs_to.rb', line 50 def column_name @column_name ||= "#{ name }_uuid" end |