Module: Tanker::Utilities

Defined in:
lib/tanker/utilities.rb

Class Method Summary collapse

Class Method Details

.clear_all_indexesObject



12
13
14
15
16
# File 'lib/tanker/utilities.rb', line 12

def clear_all_indexes
  get_available_indexes.each do |index_name|
    clear_index(index_name)
  end
end

.clear_index(index_name) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/tanker/utilities.rb', line 18

def clear_index(index_name)
  begin
    index = Tanker.api.get_index(index_name)

    if index.exists?
      puts "Deleting #{index_name} index"
      index.delete_index()
    end
    puts "Creating #{index_name} index"
    index.create_index()
    puts "Waiting for the index to be ready"
    while not index.running?
      sleep 0.5
    end
  rescue => e
    puts "There was an error clearing or creating the #{index_name} index: #{e.to_s}"
  end
end

.get_available_indexesObject



8
9
10
# File 'lib/tanker/utilities.rb', line 8

def get_available_indexes
  get_model_classes.map{|model| model.tanker_config.index_name}.uniq.compact
end

.get_model_classesObject



4
5
6
# File 'lib/tanker/utilities.rb', line 4

def get_model_classes
  Tanker.included_in ? Tanker.included_in : []
end

.reindex_all_modelsObject



37
38
39
40
41
# File 'lib/tanker/utilities.rb', line 37

def reindex_all_models
  get_model_classes.each do |klass|
    klass.tanker_reindex
  end
end