class ROM::Header

Header provides information about data mapping of a specific relation

Processors use headers to build objects that process raw relations that go through mappers.

@private

Constants

Array

Array is an embedded attribute type

Combined

Combined is an embedded attribute type describing combination of multiple relations

Exclude

Exclude is a special type of Attribute to be removed

Fold

Fold is a special type of Array attribute that requires folding transformation

Group

Group is a special type of Array attribute that requires grouping transformation

Hash

Hash is an embedded attribute type

TYPE_MAP

TYPE_MAP is a (hash) map of ROM::Header identifiers to ROM::Header types

@private

Unfold

Unfold is a special type of Array attribute that requires unfolding transformation

Ungroup

Ungroup is a special type of Array attribute that requires ungrouping transformation

Unwrap

Unwrap is a special type of Hash attribute that requires unwrapping transformation

Wrap

Wrap is a special type of Hash attribute that requires wrapping transformation

Attributes

attributes[R]

@api private

copy_keys[R]

@api private

mapping[R]

@return [Hash] attribute key/name mapping for all primitive attributes

@api private

model[R]

@return [Class] optional model associated with a header

@api private

pop_keys[R]

@return [Array] all attribute names that are popping from a tuple

@api private

reject_keys[R]

@api private

tuple_keys[R]

@return [Array] all attribute keys that are in a tuple

@api private

Public Class Methods

coerce(input, options = {}) click to toggle source

Coerce array with attribute definitions into a header object

@param [Array<Array>] input attribute name/option pairs

@param [Class] model optional

@return [Header]

@api private

# 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
new(attributes, options = {}) click to toggle source

@api private

# 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

Public Instance Methods

[](name) click to toggle source

Return attribute identified by its name

@return [Attribute]

@api private

# File lib/rom/header.rb, line 107
def [](name)
  attributes.fetch(name)
end
aliased?() click to toggle source

Return if there are any aliased attributes

@api private

# File lib/rom/header.rb, line 89
def aliased?
  any?(&:aliased?)
end
combined() click to toggle source

Return all Combined attributes

@return [Array<Combined>]

@api private

# File lib/rom/header.rb, line 116
def combined
  by_type(Combined)
end
each() { |attribute| ... } click to toggle source

Iterate over attributes

@yield [Attribute]

@api private

# File lib/rom/header.rb, line 82
def each
  attributes.each_value { |attribute| yield(attribute) }
end
keys() click to toggle source

Return attribute keys

An attribute key corresponds to tuple attribute names

@api private

# File lib/rom/header.rb, line 98
def keys
  attributes.keys
end
non_primitives() click to toggle source

Return all non-primitive attributes that don't require mapping

@return [Array<Group,Fold,Ungroup,Unfold,Wrap,Unwrap>]

@api private

# File lib/rom/header.rb, line 152
def non_primitives
  preprocessed + wraps
end
postprocessed() click to toggle source

Returns all attributes that require postprocessing

@return [Array<Ungroup,Unfold>]

@api private

# File lib/rom/header.rb, line 134
def postprocessed
  by_type(Ungroup, Unfold)
end
preprocessed() click to toggle source

Returns all attributes that require preprocessing

@return [Array<Group,Fold>]

@api private

# File lib/rom/header.rb, line 125
def preprocessed
  by_type(Group, Fold)
end
primitives() click to toggle source

Return all primitive attributes that require mapping

@return [Array<Attribute>]

@api private

# File lib/rom/header.rb, line 161
def primitives
  to_a - non_primitives
end
wraps() click to toggle source

Return all Wrap attributes

@return [Array<Wrap>]

@api private

# File lib/rom/header.rb, line 143
def wraps
  by_type(Wrap)
end

Private Instance Methods

by_type(*types) click to toggle source

Find all attribute matching specific attribute class (not kind)

@return [Array<Attribute>]

@api private

# File lib/rom/header.rb, line 172
def by_type(*types)
  select { |attribute| types.include?(attribute.class) }
end
initialize_mapping() click to toggle source

Set mapping hash from primitive attributes

@api private

# File lib/rom/header.rb, line 179
def initialize_mapping
  @mapping = primitives.map(&:mapping).reduce(:merge) || {}
end
initialize_pop_keys() click to toggle source

Set all tuple keys from all attributes popping from Unwrap and Ungroup

@api private

# File lib/rom/header.rb, line 193
def initialize_pop_keys
  @pop_keys = mapping.values + non_primitives.flat_map(&:tuple_keys)
end
initialize_tuple_keys() click to toggle source

Set all tuple keys from all attributes going deep into Wrap and Group too

@api private

# File lib/rom/header.rb, line 186
def initialize_tuple_keys
  @tuple_keys = mapping.keys.flatten + non_primitives.flat_map(&:tuple_keys)
end