Class: ROM::Header

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/rom/header.rb,
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

Classes: Attribute, Embedded

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
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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.



65
66
67
68
69
70
71
72
73
74
75
# File 'lib/rom/header.rb', line 65

def initialize(attributes, options = {})
  @options = options
  @model = options[:model]
  @copy_keys = options.fetch(:copy_keys, false)
  @reject_keys = options.fetch(:reject_keys, false)

  @attributes = attributes
  initialize_mapping
  initialize_tuple_keys
  initialize_pop_keys
end

Instance Attribute Details

#attributesObject (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.



26
27
28
# File 'lib/rom/header.rb', line 26

def attributes
  @attributes
end

#copy_keysObject (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.



23
24
25
# File 'lib/rom/header.rb', line 23

def copy_keys
  @copy_keys
end

#mappingHash (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.

Returns:

  • (Hash)

    attribute key/name mapping for all primitive attributes



31
32
33
# File 'lib/rom/header.rb', line 31

def mapping
  @mapping
end

#modelClass (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.

Returns:

  • (Class)

    optional model associated with a header



17
18
19
# File 'lib/rom/header.rb', line 17

def model
  @model
end

#pop_keysArray (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.

Returns:

  • (Array)

    all attribute names that are popping from a tuple



41
42
43
# File 'lib/rom/header.rb', line 41

def pop_keys
  @pop_keys
end

#reject_keysObject (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.



20
21
22
# File 'lib/rom/header.rb', line 20

def reject_keys
  @reject_keys
end

#tuple_keysArray (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.

Returns:

  • (Array)

    all attribute keys that are in a tuple



36
37
38
# File 'lib/rom/header.rb', line 36

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

Parameters:

  • input (Array<Array>)

    attribute name/option pairs

  • model (Class)

    optional

Returns:



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/rom/header.rb', line 52

def self.coerce(input, options = {})
  if input.instance_of?(self)
    input
  else
    attributes = input.each_with_object({}) { |pair, h|
      h[pair.first] = Attribute.coerce(pair)
    }

    new(attributes, options)
  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

Returns:



107
108
109
# File 'lib/rom/header.rb', line 107

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

Returns:

  • (Boolean)


89
90
91
# File 'lib/rom/header.rb', line 89

def aliased?
  any?(&:aliased?)
end

#combinedArray<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

Returns:



116
117
118
# File 'lib/rom/header.rb', line 116

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

Yields:



82
83
84
# File 'lib/rom/header.rb', line 82

def each
  attributes.each_value { |attribute| yield(attribute) }
end

#keysObject

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



98
99
100
# File 'lib/rom/header.rb', line 98

def keys
  attributes.keys
end

#non_primitivesArray<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



152
153
154
# File 'lib/rom/header.rb', line 152

def non_primitives
  preprocessed + wraps
end

#postprocessedArray<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

Returns:



134
135
136
# File 'lib/rom/header.rb', line 134

def postprocessed
  by_type(Ungroup, Unfold)
end

#preprocessedArray<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

Returns:



125
126
127
# File 'lib/rom/header.rb', line 125

def preprocessed
  by_type(Group, Fold)
end

#primitivesArray<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

Returns:



161
162
163
# File 'lib/rom/header.rb', line 161

def primitives
  to_a - non_primitives
end

#wrapsArray<Wrap>

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 Wrap attributes

Returns:



143
144
145
# File 'lib/rom/header.rb', line 143

def wraps
  by_type(Wrap)
end