Sha256: 19c375494342dad2dc81d9582112869e4aa918dc9e1998cb9829fab666e4c444

Contents?: true

Size: 1.25 KB

Versions: 30

Compression:

Stored size: 1.25 KB

Contents

module Gummi
  module DbLayer
    module Document
      module Attributes
        extend ActiveSupport::Concern

        module ClassMethods

          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

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

        end

      end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
gummi-1.0.10 lib/gummi/db_layer/document/attributes.rb
gummi-1.0.9 lib/gummi/db_layer/document/attributes.rb
gummi-1.0.8 lib/gummi/db_layer/document/attributes.rb
gummi-1.0.7 lib/gummi/db_layer/document/attributes.rb
gummi-1.0.6 lib/gummi/db_layer/document/attributes.rb
gummi-1.0.5 lib/gummi/db_layer/document/attributes.rb
gummi-1.0.4 lib/gummi/db_layer/document/attributes.rb
gummi-0.3.16 lib/gummi/db_layer/document/attributes.rb
gummi-1.0.3 lib/gummi/db_layer/document/attributes.rb
gummi-1.0.2 lib/gummi/db_layer/document/attributes.rb
gummi-1.0.0 lib/gummi/db_layer/document/attributes.rb
gummi-0.3.14 lib/gummi/db_layer/document/attributes.rb
gummi-0.3.13 lib/gummi/db_layer/document/attributes.rb
gummi-0.3.12 lib/gummi/db_layer/document/attributes.rb
gummi-0.3.11 lib/gummi/db_layer/document/attributes.rb
gummi-0.3.10 lib/gummi/db_layer/document/attributes.rb
gummi-0.3.9 lib/gummi/db_layer/document/attributes.rb
gummi-0.3.8 lib/gummi/db_layer/document/attributes.rb
gummi-0.3.7 lib/gummi/db_layer/document/attributes.rb
gummi-0.3.6 lib/gummi/db_layer/document/attributes.rb