Class: Anima::Attribute
- Inherits:
-
Object
- Object
- Anima::Attribute
- Includes:
- Adamantium::Flat
- Defined in:
- lib/anima/attribute.rb
Overview
An attribute
Instance Attribute Summary collapse
-
#instance_variable_name ⇒ Symbol
readonly
private
Return instance variable name.
-
#name ⇒ Symbol
readonly
private
Return attribute name.
Instance Method Summary collapse
-
#get(object) ⇒ Object
private
Get attribute value from object.
-
#initialize(name) ⇒ Attribute
constructor
private
Initialize attribute.
-
#load(object, attributes) ⇒ self
private
Load attribute.
-
#set(object, value) ⇒ self
private
Set attribute value in object.
Constructor Details
#initialize(name) ⇒ Attribute
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initialize attribute
14 15 16 |
# File 'lib/anima/attribute.rb', line 14 def initialize(name) @name, @instance_variable_name = name, :"@#{name}" end |
Instance Attribute Details
#instance_variable_name ⇒ Symbol (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return instance variable name
32 33 34 |
# File 'lib/anima/attribute.rb', line 32 def instance_variable_name @instance_variable_name end |
#name ⇒ Symbol (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return attribute name
24 25 26 |
# File 'lib/anima/attribute.rb', line 24 def name @name end |
Instance Method Details
#get(object) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get attribute value from object
55 56 57 |
# File 'lib/anima/attribute.rb', line 55 def get(object) object.public_send(name) end |
#load(object, attributes) ⇒ self
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Load attribute
43 44 45 |
# File 'lib/anima/attribute.rb', line 43 def load(object, attributes) set(object, attributes.fetch(name)) end |
#set(object, value) ⇒ self
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Set attribute value in object
68 69 70 71 72 |
# File 'lib/anima/attribute.rb', line 68 def set(object, value) object.instance_variable_set(instance_variable_name, value) self end |