123456789_123456789_123456789_123456789_123456789_

Module: Mongoid::Indexable::Validators::Options

Relationships & Source Files
Defined in: lib/mongoid/indexable/validators/options.rb

Overview

Validates the options passed to the index macro.

Constant Summary

Instance Method Summary

Instance Method Details

#validate(klass, spec, options)

Validate the index specification.

Examples:

Validate the index spec.

Options.validate(Band, name: 1)

Parameters:

  • klass (Class)

    The model class.

  • spec (Hash)

    The index specification.

  • options (Hash)

    The index options.

Raises:

[ GitHub ]

  
# File 'lib/mongoid/indexable/validators/options.rb', line 56

def validate(klass, spec, options)
  validate_spec(klass, spec, options)
  validate_options(klass, spec, options)
end

#validate_options(klass, spec, options) (private)

This method is for internal use only.

Validates the options of the index spec.

Examples:

Validate the options.

Options.validate_options(Band, name: 1)

Parameters:

  • klass (Class)

    The model class.

  • spec (Hash)

    The index specification.

  • options (Hash)

    The index options.

Raises:

[ GitHub ]

  
# File 'lib/mongoid/indexable/validators/options.rb', line 75

def validate_options(klass, spec, options)
  options.each_pair do |name, value|
    unless VALID_OPTIONS.include?(name)
      raise Errors::InvalidIndex.new(klass, spec, options)
    end
  end
end

#validate_spec(klass, spec, options) (private)

This method is for internal use only.

Validates the index spec.

Examples:

Validate the spec.

Options.validate_spec(Band, name: 1)

Parameters:

  • klass (Class)

    The model class.

  • spec (Hash)

    The index specification.

  • options (Hash)

    The index options.

Raises:

[ GitHub ]

  
# File 'lib/mongoid/indexable/validators/options.rb', line 95

def validate_spec(klass, spec, options)
  raise Errors::InvalidIndex.new(klass, spec, options) if !spec.is_a?(::Hash)
  spec.each_pair do |name, value|
    next if name == :options
    unless VALID_TYPES.include?(value)
      raise Errors::InvalidIndex.new(klass, spec, options)
    end

    if value == "geoHaystack"
      Mongoid::Warnings.warn_geo_haystack_deprecated
    end
  end
end