Class: Datamappify::Entity::Composable::Attributes

Inherits:
Object
  • Object
show all
Defined in:
lib/datamappify/entity/composable/attributes.rb

Class Method Summary collapse

Class Method Details

.build(entity, entity_class, options) ⇒ Object



6
7
8
9
10
11
12
# 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

.build_attribute(attribute_name, attribute_writer) ⇒ Virtus::Attribute (private)

Parameters:

  • attribute_name (Symbol)
  • attribute_writer (Virtus::Attribute::Writer)

Returns:

  • (Virtus::Attribute)


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# 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_attributesObject (private)



17
18
19
20
21
22
23
# 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_attributesArray (private)

Returns:

  • (Array)


26
27
28
# File 'lib/datamappify/entity/composable/attributes.rb', line 26

def excluded_attributes
  @excluded_attributes ||= @entity_class.reference_keys << :id
end