Sha256: 3981131fdfbdff6a99ca20f27f7aea2b51f696d2f8a853d135c38048684e494f

Contents?: true

Size: 725 Bytes

Versions: 17

Compression:

Stored size: 725 Bytes

Contents

# frozen_string_literal: true

class ThinkingSphinx::Configuration::DuplicateNames
  def initialize(indices)
    @indices = indices
  end

  def reconcile
    indices.each do |index|
      return if index.distributed?

      counts_for(index).each do |name, count|
        next if count <= 1

        raise ThinkingSphinx::DuplicateNameError,
          "Duplicate field/attribute name '#{name}' in index '#{index.name}'"
      end
    end
  end

  private

  attr_reader :indices

  def counts_for(index)
    names_for(index).inject({}) do |hash, name|
      hash[name] ||= 0
      hash[name] += 1
      hash
    end
  end

  def names_for(index)
    index.fields.collect(&:name) + index.attributes.collect(&:name)
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
thinking-sphinx-5.6.0 lib/thinking_sphinx/configuration/duplicate_names.rb
thinking-sphinx-5.5.1 lib/thinking_sphinx/configuration/duplicate_names.rb
thinking-sphinx-5.5.0 lib/thinking_sphinx/configuration/duplicate_names.rb
thinking-sphinx-5.4.0 lib/thinking_sphinx/configuration/duplicate_names.rb
thinking-sphinx-5.3.0 lib/thinking_sphinx/configuration/duplicate_names.rb
thinking-sphinx-5.2.1 lib/thinking_sphinx/configuration/duplicate_names.rb
thinking-sphinx-5.2.0 lib/thinking_sphinx/configuration/duplicate_names.rb
thinking-sphinx-5.1.0 lib/thinking_sphinx/configuration/duplicate_names.rb
thinking-sphinx-5.0.0 lib/thinking_sphinx/configuration/duplicate_names.rb
thinking-sphinx-4.4.1 lib/thinking_sphinx/configuration/duplicate_names.rb
thinking-sphinx-4.4.0 lib/thinking_sphinx/configuration/duplicate_names.rb
thinking-sphinx-4.3.2 lib/thinking_sphinx/configuration/duplicate_names.rb
thinking-sphinx-4.3.1 lib/thinking_sphinx/configuration/duplicate_names.rb
thinking-sphinx-4.3.0 lib/thinking_sphinx/configuration/duplicate_names.rb
thinking-sphinx-4.2.0 lib/thinking_sphinx/configuration/duplicate_names.rb
thinking-sphinx-4.1.0 lib/thinking_sphinx/configuration/duplicate_names.rb
thinking-sphinx-4.0.0 lib/thinking_sphinx/configuration/duplicate_names.rb