Class: Guacamole::DocumentModelMapper::Attribute
- Inherits:
-
Object
- Object
- Guacamole::DocumentModelMapper::Attribute
- Defined in:
- lib/guacamole/document_model_mapper.rb
Overview
An attribute to encapsulate special mapping
Instance Attribute Summary collapse
-
#name ⇒ Symbol
readonly
The name of the attribute with in the model.
-
#options ⇒ Hash
readonly
Additional options to be used for the mapping.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
To Attribute instances are equal if their name is equal.
-
#edge_class ⇒ Edge
The edge class to be used during the mapping process.
- #get_value(model) ⇒ Object
-
#getter ⇒ Object
The name of the getter for this attribute.
-
#initialize(name, options = {}) ⇒ Attribute
constructor
Create a new attribute instance.
- #inverse? ⇒ Boolean
-
#map_via_edge? ⇒ Boolean
Should this attribute be mapped via an Edge in a Graph?.
-
#setter ⇒ String
The name of the setter for this attribute.
Constructor Details
#initialize(name, options = {}) ⇒ Attribute
Create a new attribute instance
You must at least provide the name of the attribute to be mapped and optionally pass configuration for the mapper when it processes this attribute.
34 35 36 37 |
# File 'lib/guacamole/document_model_mapper.rb', line 34 def initialize(name, = {}) @name = name.to_sym @options = end |
Instance Attribute Details
#name ⇒ Symbol (readonly)
The name of the attribute with in the model
19 20 21 |
# File 'lib/guacamole/document_model_mapper.rb', line 19 def name @name end |
#options ⇒ Hash (readonly)
Additional options to be used for the mapping
24 25 26 |
# File 'lib/guacamole/document_model_mapper.rb', line 24 def @options end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
To Attribute instances are equal if their name is equal
81 82 83 84 |
# File 'lib/guacamole/document_model_mapper.rb', line 81 def ==(other) other.instance_of?(self.class) && other.name == name end |
#edge_class ⇒ Edge
The edge class to be used during the mapping process
69 70 71 |
# File 'lib/guacamole/document_model_mapper.rb', line 69 def edge_class [:via] end |
#get_value(model) ⇒ Object
46 47 48 49 50 |
# File 'lib/guacamole/document_model_mapper.rb', line 46 def get_value(model) value = model.send(getter) value.is_a?(Guacamole::Query) ? value.entries : value end |
#getter ⇒ Object
The name of the getter for this attribute
42 43 44 |
# File 'lib/guacamole/document_model_mapper.rb', line 42 def getter name end |
#inverse? ⇒ Boolean
73 74 75 |
# File 'lib/guacamole/document_model_mapper.rb', line 73 def inverse? !![:inverse] end |
#map_via_edge? ⇒ Boolean
Should this attribute be mapped via an Edge in a Graph?
62 63 64 |
# File 'lib/guacamole/document_model_mapper.rb', line 62 def map_via_edge? !!edge_class end |
#setter ⇒ String
The name of the setter for this attribute
55 56 57 |
# File 'lib/guacamole/document_model_mapper.rb', line 55 def setter "#{name}=" end |