class ThinkingSphinx::Configuration::DuplicateNames

Attributes

indices[R]

Public Class Methods

new(indices) click to toggle source
# File lib/thinking_sphinx/configuration/duplicate_names.rb, line 2
def initialize(indices)
  @indices = indices
end

Public Instance Methods

reconcile() click to toggle source
# File lib/thinking_sphinx/configuration/duplicate_names.rb, line 6
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 Instance Methods

counts_for(index) click to toggle source
# File lib/thinking_sphinx/configuration/duplicate_names.rb, line 23
def counts_for(index)
  names_for(index).inject({}) do |hash, name|
    hash[name] ||= 0
    hash[name] += 1
    hash
  end
end
names_for(index) click to toggle source
# File lib/thinking_sphinx/configuration/duplicate_names.rb, line 31
def names_for(index)
  index.fields.collect(&:name) + index.attributes.collect(&:name)
end