Sha256: c3fc963c5b17ec8b62949ddc6d6277ec557b940dce06d16dd703fd99600c9a37

Contents?: true

Size: 991 Bytes

Versions: 5

Compression:

Stored size: 991 Bytes

Contents

module Elastic::Types
  class BaseType < Elastic::Core::Serializer
    def self.target=(_name_or_class)
      pre_definition.target = _name_or_class
    end

    def self.pre_definition
      @pre_definition ||= Elastic::Core::Definition.new.tap do |definition|
        definition.target = default_target unless default_target.nil?
      end
    end

    def self.definition
      @definition ||= begin
        pre_definition.fields.each do |field|
          field.disable_mapping_inference if original_value_occluded? field.name
        end

        pre_definition.freeze
        pre_definition
      end
    end

    def self.freeze_definition
      definition # calling definition freezes it
    end

    def initialize(_object)
      super(self.class.definition, _object)
    end

    def self.default_target
      @default_target ||= begin
        target = to_s.match(/^(.*)Index$/)
        target ? target[1] : nil
      end
    end

    private_class_method :default_target
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
elastic-rails-1.0.4 lib/elastic/types/base_type.rb
elastic-rails-1.0.3 lib/elastic/types/base_type.rb
elastic-rails-1.0.2 lib/elastic/types/base_type.rb
elastic-rails-1.0.1 lib/elastic/types/base_type.rb
elastic-rails-1.0.0 lib/elastic/types/base_type.rb