class ROM::Header::Attribute

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.

@private

Attributes

key[R]

@return [Symbol] key of an attribute that corresponds to tuple attribute

@api private

meta[R]

@return [Hash] additional meta information

@api private

name[R]

@return [Symbol] name of an attribute

@api private

type[R]

@return [Symbol] type identifier (defaults to :object)

@api private

Public Class Methods

[](meta) click to toggle source

Return attribute class for a given meta hash

@param [Hash] meta hash with type information and optional transformation info

@return [Class]

@api private

# File lib/rom/header/attribute.rb, line 45
def self.[](meta)
  key = (meta.keys & TYPE_MAP.keys).first
  TYPE_MAP.fetch(key || meta[:type], self)
end
coerce(input) click to toggle source

Coerce an array with attribute meta-data into an attribute object

@param [Array<Symbol,Hash>] input attribute name/options pair

@return [Attribute]

@api private

# File lib/rom/header/attribute.rb, line 57
def self.coerce(input)
  name = input[0]
  meta = (input[1] || {}).dup

  meta[:type] ||= :object

  meta[:header] = Header.coerce(meta[:header], model: meta[:model]) if meta.key?(:header)

  self[meta].new(name, meta)
end
new(name, meta) click to toggle source

@api private

# File lib/rom/header/attribute.rb, line 69
def initialize(name, meta)
  @name = name
  @meta = meta
  @key = meta.fetch(:from) { name }
  @type = meta.fetch(:type)
end

Public Instance Methods

aliased?() click to toggle source

Return if an attribute should be aliased

@api private

# File lib/rom/header/attribute.rb, line 86
def aliased?
  key != name
end
mapping() click to toggle source

Return :key-to-:name mapping hash

@return [Hash]

@api private

# File lib/rom/header/attribute.rb, line 95
def mapping
  { key => name }
end
typed?() click to toggle source

Return if an attribute has a specific type identifier

@api private

# File lib/rom/header/attribute.rb, line 79
def typed?
  type != :object
end
union?() click to toggle source
# File lib/rom/header/attribute.rb, line 99
def union?
  key.is_a? ::Array
end