class Mongoid::Giza::Index::Attribute

Represents a Sphinx index attribute

Constants

TYPES

Defines the array of currently supported Sphix attribute types

Attributes

bits[RW]
block[RW]
default[RW]
name[R]
type[R]

Public Class Methods

new(name, type, options = {}, &block) click to toggle source

Creates a new attribute with name, type and an optional block

If a block is given then it will be evaluated for each instance of the

class being indexed and the resulting value will be the attribute
value.

Otherwise the attribute value will be the value of the corresponding

object field

@param name [Symbol] the name of the attribute @param type [Symbol] the type of the attribute. Must be one of the

types defined in {Mongoid::Giza::Index::Attribute::TYPES}

@param block [Proc] an optional block to be evaluated at the scope of

the document on index creation

@raise [TypeError] if the type is not valid. (see

{Mongoid::Giza::Index::Attribute::TYPES})
# File lib/mongoid/giza/index/attribute.rb, line 33
def initialize(name, type, options = {}, &block)
  unless TYPES.include? type
    raise TypeError,
          "Attribute type not supported. It must be one of the " \
          "following: #{TYPES.join(', ')}"
  end
  @name = normalize(name)
  @type = type
  @block = block
  @default = options[:default]
  @bits = options[:bits] if type == :uint
end