Module: Chewy::Type::Observe::MongoidMethods

Defined in:
lib/chewy/type/observe.rb

Instance Method Summary collapse

Instance Method Details

#update_index(type_name, *args, &block) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/chewy/type/observe.rb', line 7

def update_index(type_name, *args, &block)
  options = args.extract_options!
  method = args.first

  update = Proc.new do
    backreference = if method && method.to_s == 'self'
      self
    elsif method
      send(method)
    else
      instance_eval(&block)
    end

    Chewy.derive_type(type_name).update_index(backreference, options)
  end

  after_save &update
  after_destroy &update
end