Class: ROM::Header
- Inherits:
-
Object
- Object
- ROM::Header
- Includes:
- Enumerable
- Defined in:
- core/lib/rom/header.rb,
core/lib/rom/header/attribute.rb
Overview
Header provides information about data mapping of a specific relation
Processors use headers to build objects that process raw relations that go through mappers.
Defined Under Namespace
Constant Summary collapse
- Array =
Array is an embedded attribute type
Class.new(Embedded)
- Hash =
Hash is an embedded attribute type
Class.new(Embedded)
- Combined =
Combined is an embedded attribute type describing combination of multiple relations
Class.new(Embedded)
- Wrap =
Wrap is a special type of Hash attribute that requires wrapping transformation
Class.new(Hash)
- Unwrap =
Unwrap is a special type of Hash attribute that requires unwrapping transformation
Class.new(Hash)
- Group =
Group is a special type of Array attribute that requires grouping transformation
Class.new(Array)
- Ungroup =
Ungroup is a special type of Array attribute that requires ungrouping transformation
Class.new(Array)
- Fold =
Fold is a special type of Array attribute that requires folding transformation
Class.new(Array)
- Unfold =
Unfold is a special type of Array attribute that requires unfolding transformation
Class.new(Array)
- Exclude =
Exclude is a special type of Attribute to be removed
Class.new(Attribute)
- TYPE_MAP =
TYPE_MAP is a (hash) map of ROM::Header identifiers to ROM::Header types
{ combine: Combined, wrap: Wrap, unwrap: Unwrap, group: Group, ungroup: Ungroup, fold: Fold, unfold: Unfold, hash: Hash, array: Array, exclude: Exclude }.freeze
Instance Attribute Summary collapse
- #attributes ⇒ Object readonly private
- #copy_keys ⇒ Object readonly private
-
#mapping ⇒ Hash
readonly
private
Attribute key/name mapping for all primitive attributes.
-
#model ⇒ Class
readonly
private
Optional model associated with a header.
-
#pop_keys ⇒ Array
readonly
private
All attribute names that are popping from a tuple.
- #reject_keys ⇒ Object readonly private
-
#tuple_keys ⇒ Array
readonly
private
All attribute keys that are in a tuple.
Class Method Summary collapse
-
.coerce(input, options = {}) ⇒ Header
private
Coerce array with attribute definitions into a header object.
Instance Method Summary collapse
-
#[](name) ⇒ Attribute
private
Return attribute identified by its name.
-
#aliased? ⇒ Boolean
private
Return if there are any aliased attributes.
-
#combined ⇒ Array<Combined>
private
Return all Combined attributes.
-
#each {|Attribute| ... } ⇒ Object
private
Iterate over attributes.
-
#initialize(attributes, options = {}) ⇒ Header
constructor
private
A new instance of Header.
-
#keys ⇒ Object
private
Return attribute keys.
-
#non_primitives ⇒ Array<Group,Fold,Ungroup,Unfold,Wrap,Unwrap>
private
Return all non-primitive attributes that don't require mapping.
-
#postprocessed ⇒ Array<Ungroup,Unfold>
private
Returns all attributes that require postprocessing.
-
#preprocessed ⇒ Array<Group,Fold>
private
Returns all attributes that require preprocessing.
-
#primitives ⇒ Array<Attribute>
private
Return all primitive attributes that require mapping.
-
#wraps ⇒ Array<Wrap>
private
Return all Wrap attributes.
Constructor Details
#initialize(attributes, options = {}) ⇒ Header
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 Header.
66 67 68 69 70 71 72 73 74 75 76 |
# File 'core/lib/rom/header.rb', line 66 def initialize(attributes, = {}) @options = @model = [:model] @copy_keys = .fetch(:copy_keys, false) @reject_keys = .fetch(:reject_keys, false) @attributes = attributes initialize_mapping initialize_tuple_keys initialize_pop_keys end |
Instance Attribute Details
#attributes ⇒ Object (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.
28 29 30 |
# File 'core/lib/rom/header.rb', line 28 def attributes @attributes end |
#copy_keys ⇒ Object (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.
25 26 27 |
# File 'core/lib/rom/header.rb', line 25 def copy_keys @copy_keys end |
#mapping ⇒ 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 attribute key/name mapping for all primitive attributes.
33 34 35 |
# File 'core/lib/rom/header.rb', line 33 def mapping @mapping end |
#model ⇒ Class (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 optional model associated with a header.
19 20 21 |
# File 'core/lib/rom/header.rb', line 19 def model @model end |
#pop_keys ⇒ Array (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 all attribute names that are popping from a tuple.
43 44 45 |
# File 'core/lib/rom/header.rb', line 43 def pop_keys @pop_keys end |
#reject_keys ⇒ Object (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.
22 23 24 |
# File 'core/lib/rom/header.rb', line 22 def reject_keys @reject_keys end |
#tuple_keys ⇒ Array (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 all attribute keys that are in a tuple.
38 39 40 |
# File 'core/lib/rom/header.rb', line 38 def tuple_keys @tuple_keys end |
Class Method Details
.coerce(input, options = {}) ⇒ Header
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 array with attribute definitions into a header object
53 54 55 56 57 58 59 60 61 62 63 |
# File 'core/lib/rom/header.rb', line 53 def self.coerce(input, = {}) if input.instance_of?(self) input else attributes = input.each_with_object({}) { |pair, h| h[pair.first] = Attribute.coerce(pair) } new(attributes, ) end end |
Instance Method Details
#[](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.
Return attribute identified by its name
108 109 110 |
# File 'core/lib/rom/header.rb', line 108 def [](name) attributes.fetch(name) end |
#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 there are any aliased attributes
90 91 92 |
# File 'core/lib/rom/header.rb', line 90 def aliased? any?(&:aliased?) end |
#combined ⇒ Array<Combined>
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 all Combined attributes
117 118 119 |
# File 'core/lib/rom/header.rb', line 117 def combined by_type(Combined) end |
#each {|Attribute| ... } ⇒ 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.
Iterate over attributes
83 84 85 |
# File 'core/lib/rom/header.rb', line 83 def each attributes.each_value { |attribute| yield(attribute) } end |
#keys ⇒ 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.
Return attribute keys
An attribute key corresponds to tuple attribute names
99 100 101 |
# File 'core/lib/rom/header.rb', line 99 def keys attributes.keys end |
#non_primitives ⇒ Array<Group,Fold,Ungroup,Unfold,Wrap,Unwrap>
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 all non-primitive attributes that don't require mapping
153 154 155 |
# File 'core/lib/rom/header.rb', line 153 def non_primitives preprocessed + wraps end |
#postprocessed ⇒ Array<Ungroup,Unfold>
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 all attributes that require postprocessing
135 136 137 |
# File 'core/lib/rom/header.rb', line 135 def postprocessed by_type(Ungroup, Unfold) end |
#preprocessed ⇒ Array<Group,Fold>
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 all attributes that require preprocessing
126 127 128 |
# File 'core/lib/rom/header.rb', line 126 def preprocessed by_type(Group, Fold) end |
#primitives ⇒ Array<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.
Return all primitive attributes that require mapping
162 163 164 |
# File 'core/lib/rom/header.rb', line 162 def primitives to_a - non_primitives end |