Class: Anima::Attribute
- Inherits:
-
Object
- Object
- Anima::Attribute
- Includes:
- Adamantium::Flat
- Defined in:
- lib/anima/attribute.rb
Overview
An attribute
Instance Attribute Summary collapse
-
#name ⇒ Symbol
readonly
private
Return attribute name.
Instance Method Summary collapse
-
#define_reader(scope) ⇒ self
private
Define reader.
-
#get(object) ⇒ Object
private
Get attribute value from object.
-
#initialize(name) ⇒ Attribute
constructor
private
Initialize attribute.
-
#instance_variable_name ⇒ Symbol
private
Return instance variable name.
-
#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
13 14 15 |
# File 'lib/anima/attribute.rb', line 13 def initialize(name) @name = name end |
Instance Attribute Details
#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
23 24 25 |
# File 'lib/anima/attribute.rb', line 23 def name @name end |
Instance Method Details
#define_reader(scope) ⇒ 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.
Define reader
91 92 93 94 |
# File 'lib/anima/attribute.rb', line 91 def define_reader(scope) scope.send(:attr_reader, name) self end |
#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
52 53 54 |
# File 'lib/anima/attribute.rb', line 52 def get(object) object.public_send(name) end |
#instance_variable_name ⇒ Symbol
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
78 79 80 |
# File 'lib/anima/attribute.rb', line 78 def instance_variable_name :"@#{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
34 35 36 37 38 39 40 41 42 |
# File 'lib/anima/attribute.rb', line 34 def load(object, attributes) attribute_name = name value = attributes.fetch(attribute_name) do raise Error::Missing.new(object.class, attribute_name) end set(object, value) 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
65 66 67 68 69 |
# File 'lib/anima/attribute.rb', line 65 def set(object, value) object.instance_variable_set(instance_variable_name, value) self end |