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
- Fold
Fold
is a special type ofArray
attribute that requires folding transformation- Group
Group
is a special type ofArray
attribute that requires grouping transformation- Hash
Hash
is an embedded attribute type- TYPE_MAP
TYPE_MAP
is a (hash) map ofROM::Header
identifiers toROM::Header
types@private
- Unfold
Unfold
is a special type ofArray
attribute that requires unfolding transformation- Ungroup
Ungroup
is a special type ofArray
attribute that requires ungrouping transformation- Unwrap
Unwrap
is a special type ofHash
attribute that requires unwrapping transformation- Wrap
Wrap
is a special type ofHash
attribute that requires wrapping transformation
Attributes
@api private
@api private
@return [Hash] attribute key/name mapping for all primitive attributes
@api private
@return [Class] optional model associated with a header
@api private
@return [Array] all attribute names that are popping from a tuple
@api private
@api private
@return [Array] all attribute keys that are in a tuple
@api private
Public Class Methods
Coerce array with attribute definitions into a header object
@param [Array<Array>] input attribute name/option pairs @param [Hash] options
@return [Header]
@api private
# File lib/rom/header.rb, line 53 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
@api private
# File lib/rom/header.rb, line 66 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
Return attribute identified by its name
@return [Attribute]
@api private
# File lib/rom/header.rb, line 108 def [](name) attributes.fetch(name) end
Return if there are any aliased attributes
@api private
# File lib/rom/header.rb, line 90 def aliased? any?(&:aliased?) end
Return all Combined
attributes
@return [Array<Combined>]
@api private
# File lib/rom/header.rb, line 117 def combined by_type(Combined) end
Iterate over attributes
@yield [Attribute]
@api private
# File lib/rom/header.rb, line 83 def each attributes.each_value { |attribute| yield(attribute) } end
Return attribute keys
An attribute key corresponds to tuple attribute names
@api private
# File lib/rom/header.rb, line 99 def keys attributes.keys end
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 153 def non_primitives preprocessed + wraps end
Returns all attributes that require postprocessing
@return [Array<Ungroup,Unfold>]
@api private
# File lib/rom/header.rb, line 135 def postprocessed by_type(Ungroup, Unfold) end
Returns all attributes that require preprocessing
@return [Array<Group,Fold>]
@api private
# File lib/rom/header.rb, line 126 def preprocessed by_type(Group, Fold) end
Return all primitive attributes that require mapping
@return [Array<Attribute>]
@api private
# File lib/rom/header.rb, line 162 def primitives to_a - non_primitives end
Return all Wrap
attributes
@return [Array<Wrap>]
@api private
# File lib/rom/header.rb, line 144 def wraps by_type(Wrap) end
Private Instance Methods
Find all attribute matching specific attribute class (not kind)
@return [Array<Attribute>]
@api private
# File lib/rom/header.rb, line 173 def by_type(*types) select { |attribute| types.include?(attribute.class) } end
Set mapping hash from primitive attributes
@api private
# File lib/rom/header.rb, line 180 def initialize_mapping @mapping = primitives.map(&:mapping).reduce(:merge) || {} end