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.



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

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

  if scope_key
    fields.merge!({scope_key => 1})
  end

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

  return [fields, options]
end