class Datamappify::Entity::Composable::Attributes

Public Class Methods

build(entity, entity_class, options) click to toggle source
# File lib/datamappify/entity/composable/attributes.rb, line 6
def build(entity, entity_class, options)
  @entity       = entity
  @entity_class = entity_class
  @options      = options

  build_attributes
end

Private Class Methods

build_attribute(attribute_name, attribute_writer) click to toggle source

@param attribute_name [Symbol]

@param attribute_writer [Virtus::Attribute::Writer]

@return [Virtus::Attribute]

# File lib/datamappify/entity/composable/attributes.rb, line 35
def build_attribute(attribute_name, attribute_writer)
  name = if @options[:prefix_with]
    Attribute.prefix(attribute_name, @options[:prefix_with])
  else
    attribute_name
  end

  Virtus::Attribute.build(
    name,
    attribute_writer.primitive,
    :default    => attribute_writer.default_value,
    :visibility => attribute_writer.visibility,
    :coercer    => attribute_writer.coercer
  )
end
build_attributes() click to toggle source

@return (see attributes_from)

# File lib/datamappify/entity/composable/attributes.rb, line 17
def build_attributes
  @entity_class.attribute_set.each do |attribute|
    unless excluded_attributes.include?(attribute.name)
      @entity.attribute_set << build_attribute(attribute.name, attribute.writer)
    end
  end
end
excluded_attributes() click to toggle source

@return [Array]

# File lib/datamappify/entity/composable/attributes.rb, line 26
def excluded_attributes
  @excluded_attributes ||= @entity_class.reference_keys << :id
end