Module: Tanker::InstanceMethods

Defined in:
lib/tanker.rb

Overview

these are the instance methods included

Instance Method Summary collapse

Instance Method Details

#delete_tank_indexesObject

delete instance from index tank



249
250
251
# File 'lib/tanker.rb', line 249

def delete_tank_indexes
  tanker_config.index.delete_document(it_doc_id)
end

#it_doc_idObject

create a unique index based on the model name and unique id



284
285
286
# File 'lib/tanker.rb', line 284

def it_doc_id
  self.class.name + ' ' + self.id.to_s
end

#tanker_configObject



229
230
231
# File 'lib/tanker.rb', line 229

def tanker_config
  self.class.tanker_config || raise(NotConfigured, "Please configure Tanker for #{self.class.inspect} with the 'tankit' block")
end

#tanker_index_dataObject



253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
# File 'lib/tanker.rb', line 253

def tanker_index_data
  data = {}

  # attempt to autodetect timestamp
  if respond_to?(:created_at)
    data[:timestamp] = created_at.to_i
  end

  tanker_indexes.each do |field, block|
    val = block ? instance_exec(&block) : send(field)
    val = val.join(' ') if Array === val
    data[field.to_sym] = val.to_s unless val.nil?
  end

  data[:__any] = data.values.sort_by{|v| v.to_s}.join " . "
  data[:__type] = self.class.name

  data
end

#tanker_index_optionsObject



273
274
275
276
277
278
279
280
281
# File 'lib/tanker.rb', line 273

def tanker_index_options
  options = {}

  if tanker_variables
    options[:variables] = instance_exec(&tanker_variables)
  end

  options
end

#tanker_indexesObject



233
234
235
# File 'lib/tanker.rb', line 233

def tanker_indexes
  tanker_config.indexes
end

#tanker_variablesObject



237
238
239
# File 'lib/tanker.rb', line 237

def tanker_variables
  tanker_config.variables
end

#update_tank_indexesObject

update a create instance from index tank



242
243
244
245
246
# File 'lib/tanker.rb', line 242

def update_tank_indexes
  tanker_config.index.add_document(
    it_doc_id, tanker_index_data, tanker_index_options
  )
end