Module: Datamappify::Entity::Composable::DSL

Defined in:
lib/datamappify/entity/composable.rb

Instance Method Summary collapse

Instance Method Details

#attributes_from(entity_class, options = {}) ⇒ void

This method returns an undefined value.

Parameters:

  • entity_class (Entity)
  • options (Hash) (defaults to: {})


14
15
16
17
18
19
20
# File 'lib/datamappify/entity/composable.rb', line 14

def attributes_from(entity_class, options = {})
  entity_class.attribute_set.each do |attribute|
    unless excluded_attributes(entity_class).include?(attribute.name)
      self.attribute_set << tweak_attribute!(attribute, options)
    end
  end
end

#excluded_attributes(entity_class) ⇒ Array (private)

Parameters:

Returns:

  • (Array)


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

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

#prefix_attribute_name!(attribute, prefix) ⇒ void (private)

This method returns an undefined value.

Parameters:

  • attribute (Virtus::Attribute)
  • prefix (Symbol)


47
48
49
# File 'lib/datamappify/entity/composable.rb', line 47

def prefix_attribute_name!(attribute, prefix)
  attribute.instance_variable_set :@name, :"#{prefix}_#{attribute.name}"
end

#tweak_attribute!(attribute, options) ⇒ Virtus::Attribute (private)

Parameters:

  • attribute (Virtus::Attribute)
  • options (Hash)

Returns:

  • (Virtus::Attribute)


36
37
38
39
40
# File 'lib/datamappify/entity/composable.rb', line 36

def tweak_attribute!(attribute, options)
  prefix_attribute_name!(attribute, options[:prefix_with]) if options[:prefix_with]

  attribute
end