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_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) ⇒ 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.
28 29 30 |
# File 'lib/uuids/base/belongs_to.rb', line 28 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_name ⇒ String (readonly)
The name of the #klass db table column to store reference to the
attribute by uuid.
37 38 39 |
# File 'lib/uuids/base/belongs_to.rb', line 37 def column_name @column_name ||= "#{ name }_uuid" 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) ⇒ Object
Constructs the object and adds the attribute.
48 49 50 |
# File 'lib/uuids/base/belongs_to.rb', line 48 def self.add(klass, name) new(klass, name).add end |
Instance Method Details
#add ⇒ Object
Adds the attribute’s getter and setter.
58 59 60 61 62 |
# File 'lib/uuids/base/belongs_to.rb', line 58 def add 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.
37 38 39 |
# File 'lib/uuids/base/belongs_to.rb', line 37 def column_name @column_name ||= "#{ name }_uuid" end |