Module: Fuzzzy::Mongoid::Index

Extended by:
ActiveSupport::Concern
Defined in:
lib/fuzzzy/orm/mongoid/index.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#change_field_index(command, field, options) ⇒ Object



78
79
80
81
82
83
# File 'lib/fuzzzy/orm/mongoid/index.rb', line 78

def change_field_index command, field, options
  self.class.indexer(options[:method]).send(command, options.merge(
    :id => self.id,
    :dictionary_string => self.send(field)
  ))
end

#change_indexes(command, condition = nil) ⇒ Object



71
72
73
74
75
76
# File 'lib/fuzzzy/orm/mongoid/index.rb', line 71

def change_indexes command, condition=nil
  self.class.fuzzzy_indexes.each do |(field, opts)|
    change_field_index(command, field, opts.dup) if command == :delete_index ||
      self.changed.include?(field.to_s)
  end
end

#create_fuzzzy_indexes(&block) ⇒ Object



67
68
69
# File 'lib/fuzzzy/orm/mongoid/index.rb', line 67

def create_fuzzzy_indexes &block
  change_indexes(:create_index, &block)
end

#delete_fuzzzy_indexes(&block) ⇒ Object



63
64
65
# File 'lib/fuzzzy/orm/mongoid/index.rb', line 63

def delete_fuzzzy_indexes &block
  change_indexes(:delete_index, &block)
end