lib/elasticity/index_config.rb in es-elasticity-0.14.1 vs lib/elasticity/index_config.rb in es-elasticity-1.0.0.jhumphreys
- old
+ new
@@ -1,30 +1,34 @@
+# frozen_string_literal: true
+
module Elasticity
class IndexConfig
class SubclassError < StandardError; end
- SUBCLASSES_WARNING = "Indices created in Elasticsearch 6.0.0 or later may only contain a single mapping type. " +
+ SUBCLASSES_WARNING = "Indices created in Elasticsearch 6.0.0 or later may only contain a single mapping type. "\
"Therefore, doument-type based inheritance has been disabled by Elasticity"
- SUBCLASSES_ERROR = "Mapping types have been completely removed in Elasticsearch 7.0.0. " +
+ SUBCLASSES_ERROR = "Mapping types have been completely removed in Elasticsearch 7.0.0. "\
"Therefore, doument-type based inheritance has been disabled by Elasticity"
- VERSION_FOR_SUBCLASS_WARNING = "6.0.0".freeze
- VERSION_FOR_SUBCLASS_ERROR = "7.0.0".freeze
+ VERSION_FOR_SUBCLASS_WARNING = "6.0.0"
+ VERSION_FOR_SUBCLASS_ERROR = "7.0.0"
ATTRS = [
:index_base_name, :document_type, :mapping, :strategy, :subclasses,
:settings, :use_new_timestamp_format, :include_type_name_on_create
].freeze
VALIDATABLE_ATTRS = [:index_base_name, :document_type, :strategy].freeze
+ DEPRECATED_ATTRS = [:use_new_timestamp_format, :include_type_name_on_create].freeze
attr_accessor(*ATTRS)
def initialize(elasticity_config, defaults = {})
defaults.each do |k,v|
instance_variable_set("@#{k}",v)
end
@elasticity_config = elasticity_config
yield(self)
subclasses_warning_or_exception
+ warn_deprecated_config
validate!
end
def segment(name)
new_config = self.dup
@@ -36,13 +40,14 @@
@elasticity_config.client
end
def definition
return @definition if defined?(@definition)
+
@definition = {
settings: merge_settings,
- mappings: { @document_type => @mapping.nil? ? {} : @mapping.deep_stringify_keys }
+ mappings: @mapping.nil? ? {} : @mapping.deep_stringify_keys
}
subclasses.each do |doc_type, subclass|
@definition[:mappings][doc_type] = subclass.constantize.mapping
end if subclasses.present?
@definition
@@ -76,9 +81,18 @@
end
end
def merge_settings
@elasticity_config.settings.merge(settings || {})
+ end
+
+ def warn_deprecated_config
+ DEPRECATED_ATTRS.each do |attr|
+ ActiveSupport::Deprecation.warn(
+ "#{attr} is deprecated and will be "\
+ "removed in the next major release."
+ ) if public_send(attr).present?
+ end
end
def subclasses_warning_or_exception
return if subclasses.nil? || subclasses.empty?
raise(SubclassError.new(SUBCLASSES_ERROR)) if es_version_meets_or_exceeds?(VERSION_FOR_SUBCLASS_ERROR)