Sha256: 4057f5911727faf4138df5d31aec5c1a828da527563de937204e50e211c74a7b

Contents?: true

Size: 1.07 KB

Versions: 14

Compression:

Stored size: 1.07 KB

Contents

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

    def self.targets=(_names_or_classes)
      pre_definition.targets = _names_or_classes
    end

    def self.pre_definition
      @pre_definition ||= Elastic::Core::Definition.new.tap do |definition|
        definition.targets = [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

14 entries across 14 versions & 1 rubygems

Version Path
elastic-rails-0.8.7 lib/elastic/types/base_type.rb
elastic-rails-0.8.6 lib/elastic/types/base_type.rb
elastic-rails-0.8.5 lib/elastic/types/base_type.rb
elastic-rails-0.8.4 lib/elastic/types/base_type.rb
elastic-rails-0.8.3 lib/elastic/types/base_type.rb
elastic-rails-0.8.2 lib/elastic/types/base_type.rb
elastic-rails-0.8.1 lib/elastic/types/base_type.rb
elastic-rails-0.8.0 lib/elastic/types/base_type.rb
elastic-rails-0.7.0 lib/elastic/types/base_type.rb
elastic-rails-0.6.4 lib/elastic/types/base_type.rb
elastic-rails-0.6.3 lib/elastic/types/base_type.rb
elastic-rails-0.6.2 lib/elastic/types/base_type.rb
elastic-rails-0.6.1 lib/elastic/types/base_type.rb
elastic-rails-0.6.0 lib/elastic/types/base_type.rb