Module: Tanker::ClassMethods

Defined in:
lib/tanker.rb

Overview

these are the class methods added when Tanker is included They’re kept to a minimum to prevent namespace pollution

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#tanker_configObject

Returns the value of attribute tanker_config.



155
156
157
# File 'lib/tanker.rb', line 155

def tanker_config
  @tanker_config
end

Instance Method Details

#search_tank(query, options = {}) ⇒ Object



165
166
167
# File 'lib/tanker.rb', line 165

def search_tank(query, options = {})
  Tanker.search([self], query, options)
end

#tanker_indexObject



169
170
171
# File 'lib/tanker.rb', line 169

def tanker_index
  tanker_config.index
end

#tanker_reindex(options = {}) ⇒ Object



173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/tanker.rb', line 173

def tanker_reindex(options = {})
  puts "Indexing #{self} model"

  batches = []
  options[:batch_size] ||= 200
  records = options[:scope] ? send(options[:scope]).all : all
  record_size = records.size

  records.each_with_index do |model_instance, idx|
    batch_num = idx / options[:batch_size]
    (batches[batch_num] ||= []) << model_instance
  end

  timer = Time.now
  batches.each_with_index do |batch, idx|
    Tanker.batch_update(batch)
    puts "Indexed #{batch.size} records   #{(idx * options[:batch_size]) + batch.size}/#{record_size}"
  end
  puts "Indexed #{record_size} #{self} records in #{Time.now - timer} seconds"
end

#tankit(name, &block) ⇒ Object



157
158
159
160
161
162
163
# File 'lib/tanker.rb', line 157

def tankit(name, &block)
  if block_given?
    self.tanker_config = ModelConfig.new(name, block)
  else
    raise(NoBlockGiven, 'Please provide a block')
  end
end