class Mongoid::Indexable::Specification

Encapsulates behavior around an index specification.

def ==(other)

Returns:
  • (true, false) - If the specs are equal.

Parameters:
  • other (Specification) -- The spec to compare against.

Other tags:
    Example: Check equality of the specifications. -
def ==(other)
  fields == other.fields && key == other.key
end

def initialize(klass, key, opts = nil)

Parameters:
  • opts (Hash) -- the index options.
  • key (Hash) -- The hash of name/direction pairs.
  • klass (Class) -- The class the index is defined on.

Other tags:
    Example: Create the new specification. -
def initialize(klass, key, opts = nil)
  options = opts || {}
  Validators::Options.validate(klass, key, options)
  @klass = klass
  @key = normalize_key(key)
  @fields = @key.keys
  @options = normalize_options(options.dup)
end

def name

Returns:
  • (String) - name The index name.

Other tags:
    Example: Get the index name. -
def name
  @name ||= key.reduce([]) do |n, (k,v)|
    n << "#{k}_#{v}"
  end.join('_')
end

def normalize_key(key)

Returns:
  • (Hash) - The normalized specification.

Parameters:
  • key (Hash) -- The index key(s).

Other tags:
    Example: Normalize the spec. -

Other tags:
    Api: - private
def normalize_key(key)
  normalized = {}
  key.each_pair do |name, direction|
    normalized[klass.database_field_name(name).to_sym] = direction
  end
  normalized
end

def normalize_options(opts)

Returns:
  • (Hash) - The normalized options.

Parameters:
  • opts (Hash) -- The index options.

Other tags:
    Example: Normalize the index options. -

Other tags:
    Api: - private
def normalize_options(opts)
  options = {}
  opts.each_pair do |option, value|
    options[MAPPINGS[option] || option] = value
  end
  options
end