Class: ROM::Header::Attribute
- Inherits:
-
Object
- Object
- ROM::Header::Attribute
- Defined in:
- core/lib/rom/header/attribute.rb
Overview
An attribute provides information about a specific attribute in a tuple
This may include information about how an attribute should be renamed, or how its value should coerced.
More complex attributes describe how an attribute should be transformed.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#key ⇒ Symbol
readonly
private
Key of an attribute that corresponds to tuple attribute.
-
#meta ⇒ Hash
readonly
private
Additional meta information.
-
#name ⇒ Symbol
readonly
private
Name of an attribute.
-
#type ⇒ Symbol
readonly
private
Type identifier (defaults to :object).
Class Method Summary collapse
-
.[](meta) ⇒ Class
private
Return attribute class for a given meta hash.
-
.coerce(input) ⇒ Attribute
private
Coerce an array with attribute meta-data into an attribute object.
Instance Method Summary collapse
-
#aliased? ⇒ Boolean
private
Return if an attribute should be aliased.
-
#initialize(name, meta) ⇒ Attribute
constructor
private
A new instance of Attribute.
-
#mapping ⇒ Hash
private
Return :key-to-:name mapping hash.
-
#typed? ⇒ Boolean
private
Return if an attribute has a specific type identifier.
- #union? ⇒ Boolean
Constructor Details
#initialize(name, meta) ⇒ 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.
Returns a new instance of Attribute.
67 68 69 70 71 72 |
# File 'core/lib/rom/header/attribute.rb', line 67 def initialize(name, ) @name = name @meta = @key = .fetch(:from) { name } @type = .fetch(:type) end |
Instance Attribute Details
#key ⇒ 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.
Returns key of an attribute that corresponds to tuple attribute.
24 25 26 |
# File 'core/lib/rom/header/attribute.rb', line 24 def key @key end |
#meta ⇒ Hash (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.
Returns additional meta information.
34 35 36 |
# File 'core/lib/rom/header/attribute.rb', line 34 def @meta 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.
Returns name of an attribute.
19 20 21 |
# File 'core/lib/rom/header/attribute.rb', line 19 def name @name end |
#type ⇒ 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.
Returns type identifier (defaults to :object).
29 30 31 |
# File 'core/lib/rom/header/attribute.rb', line 29 def type @type end |
Class Method Details
.[](meta) ⇒ Class
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 class for a given meta hash
43 44 45 46 |
# File 'core/lib/rom/header/attribute.rb', line 43 def self.[]() key = (.keys & TYPE_MAP.keys).first TYPE_MAP.fetch(key || [:type], self) end |
.coerce(input) ⇒ 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.
Coerce an array with attribute meta-data into an attribute object
55 56 57 58 59 60 61 62 63 64 |
# File 'core/lib/rom/header/attribute.rb', line 55 def self.coerce(input) name = input[0] = (input[1] || {}).dup [:type] ||= :object [:header] = Header.coerce([:header], model: [:model]) if .key?(:header) self[].new(name, ) end |
Instance Method Details
#aliased? ⇒ Boolean
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 if an attribute should be aliased
84 85 86 |
# File 'core/lib/rom/header/attribute.rb', line 84 def aliased? key != name end |
#mapping ⇒ Hash
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 :key-to-:name mapping hash
93 94 95 |
# File 'core/lib/rom/header/attribute.rb', line 93 def mapping { key => name } end |
#typed? ⇒ Boolean
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 if an attribute has a specific type identifier
77 78 79 |
# File 'core/lib/rom/header/attribute.rb', line 77 def typed? type != :object end |
#union? ⇒ Boolean
97 98 99 |
# File 'core/lib/rom/header/attribute.rb', line 97 def union? key.is_a? ::Array end |