Module: Elastic::Railties::IndexableRecord::ClassMethods

Defined in:
lib/elastic/railties/indexable_record.rb

Instance Method Summary collapse

Instance Method Details

#constantized_index_classObject



17
18
19
# File 'lib/elastic/railties/indexable_record.rb', line 17

def constantized_index_class
  @constantized_index_class ||= index_class.constantize
end

#index(on: nil, unindex: true, delayed: true) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/elastic/railties/indexable_record.rb', line 21

def index(on: nil, unindex: true, delayed: true)
  index_m, unindex_m = delayed ? [:index_later, :unindex_later] : [:index_now, :unindex_now]

  if on == :create
    after_create { public_send(index_m) }
  elsif on == :save
    after_save { public_send(index_m) }
  else
    raise ArgumentError, 'must provide an indexing target when calling index \
(ie: `index on: :save`)'
  end

  before_destroy { public_send(unindex_m) } if unindex
end

#index_classObject



8
9
10
# File 'lib/elastic/railties/indexable_record.rb', line 8

def index_class
  @index_class ||= to_s + 'Index'
end

#index_class=(_class) ⇒ Object



12
13
14
15
# File 'lib/elastic/railties/indexable_record.rb', line 12

def index_class=(_class)
  @constantized_index_class = nil
  @index_class = _class
end