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
@return [Symbol] key of an attribute that corresponds to tuple attribute
@api private
@return [Hash] additional meta information
@api private
@return [Symbol] name of an attribute
@api private
@return [Symbol] type identifier (defaults to :object)
@api private
Public Class Methods
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 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
@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
Return if an attribute should be aliased
@api private
# File lib/rom/header/attribute.rb, line 86 def aliased? key != name end
Return :key-to-:name mapping hash
@return [Hash]
@api private
# File lib/rom/header/attribute.rb, line 95 def mapping { key => name } end
Return if an attribute has a specific type identifier
@api private
# File lib/rom/header/attribute.rb, line 79 def typed? type != :object end
# File lib/rom/header/attribute.rb, line 99 def union? key.is_a? ::Array end