Module: Gummi::DbLayer::Document::Attributes::ClassMethods

Defined in:
lib/gummi/db_layer/document/attributes.rb

Instance Method Summary collapse

Instance Method Details

#mappingObject



27
28
29
30
31
32
33
# File 'lib/gummi/db_layer/document/attributes.rb', line 27

def mapping
  result = {}
  attribute_set.each do |attribute|
    result.merge! attribute.name => mapping_for_attribute(attribute)
  end
  result
end

#mapping_for_attribute(attribute) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/gummi/db_layer/document/attributes.rb', line 9

def mapping_for_attribute(attribute)
  if attribute.is_a? Virtus::Attribute::EmbeddedValue
    { properties: attribute.primitive.mapping }
  elsif attribute.is_a? Virtus::Attribute::Collection
    mapping_for_attribute(attribute.member_type)
  else
    begin
      attribute.mapping
    rescue NoMethodError => exception
      if exception.message.include?("`mapping'")
        raise Errors::ImplicitMappingForbidden, "Sorry, you have to explicitly define the attribute type for #{attribute.instance_variable_name rescue nil} in #{self} or maybe you tried to use Array[] where it is not allowed. Original Exception: #{exception.message}"
      else
        raise exception
      end
    end
  end
end