Class: Datamappify::Entity::Composable::Attributes
- Inherits:
-
Object
- Object
- Datamappify::Entity::Composable::Attributes
- Defined in:
- lib/datamappify/entity/composable/attributes.rb
Class Method Summary collapse
- .build(entity, entity_class, options) ⇒ Object
- .build_attribute(attribute_name, attribute_writer) ⇒ Virtus::Attribute private
- .build_attributes ⇒ Object private
- .excluded_attributes ⇒ Array private
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, ) @entity = entity @entity_class = entity_class @options = build_attributes end |
.build_attribute(attribute_name, attribute_writer) ⇒ Virtus::Attribute (private)
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_attributes ⇒ Object (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_attributes ⇒ Array (private)
26 27 28 |
# File 'lib/datamappify/entity/composable/attributes.rb', line 26 def excluded_attributes @excluded_attributes ||= @entity_class.reference_keys << :id end |