Module: Mongoid::Slug::Index

Defined in:
lib/mongoid/slug/index.rb

Class Method Summary collapse

Class Method Details

.build_index(scope_key = nil, by_model_type = false) ⇒ Array(Hash, Hash)

Returns the indexable fields and index options.

Parameters:

  • scope_key (String or Symbol) (defaults to: nil)

    The optional scope key for the index

  • by_model_type (Boolean) (defaults to: false)

    Whether or not

Returns:

  • (Array(Hash, Hash))

    the indexable fields and index options.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/mongoid/slug/index.rb', line 8

def self.build_index(scope_key = nil, by_model_type = false)
  fields  = { _slugs: 1 }
  options = {}

  fields.merge!(scope_key => 1) if scope_key

  if by_model_type
    fields.merge!(_type: 1)
  else
    options.merge!(unique: true, sparse: true)
  end

  [fields, options]
end