Module: Tanker::InstanceMethods
- Defined in:
- lib/tanker.rb
Overview
these are the instance methods included
Instance Method Summary collapse
-
#create_snippet_attribute(key, value) ⇒ Object
dynamically create a snippet read attribute (method).
-
#delete_tank_indexes ⇒ Object
delete instance from index tank.
-
#it_doc_id ⇒ Object
create a unique index based on the model name and unique id.
- #tanker_config ⇒ Object
- #tanker_index_data ⇒ Object
- #tanker_index_options ⇒ Object
- #tanker_indexes ⇒ Object
- #tanker_variables ⇒ Object
- #type_name ⇒ Object
-
#update_tank_indexes ⇒ Object
update a create instance from index tank.
Instance Method Details
#create_snippet_attribute(key, value) ⇒ Object
dynamically create a snippet read attribute (method)
351 352 353 354 355 |
# File 'lib/tanker.rb', line 351 def create_snippet_attribute(key, value) # method name should something_snippet not snippet_something as the api returns it method_name = "#{key.match(/snippet_(\w+)/)[1]}_snippet" (class << self; self end).send(:define_method, method_name) { value } end |
#delete_tank_indexes ⇒ Object
delete instance from index tank
325 326 327 |
# File 'lib/tanker.rb', line 325 def delete_tank_indexes tanker_config.index.delete_document(it_doc_id) end |
#it_doc_id ⇒ Object
create a unique index based on the model name and unique id
370 371 372 |
# File 'lib/tanker.rb', line 370 def it_doc_id type_name + ' ' + self.id.to_s end |
#tanker_config ⇒ Object
305 306 307 |
# File 'lib/tanker.rb', line 305 def tanker_config self.class.tanker_config || raise(NotConfigured, "Please configure Tanker for #{self.class.inspect} with the 'tankit' block") end |
#tanker_index_data ⇒ Object
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 |
# File 'lib/tanker.rb', line 329 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] = type_name data[:__id] = self.id data end |
#tanker_index_options ⇒ Object
357 358 359 360 361 362 363 364 365 366 367 |
# File 'lib/tanker.rb', line 357 def = {} unless tanker_variables.empty? [:variables] = tanker_variables.inject({}) do |hash, variables| hash.merge(instance_exec(&variables)) end end end |
#tanker_indexes ⇒ Object
309 310 311 |
# File 'lib/tanker.rb', line 309 def tanker_indexes tanker_config.indexes end |
#tanker_variables ⇒ Object
313 314 315 |
# File 'lib/tanker.rb', line 313 def tanker_variables tanker_config.variables end |
#type_name ⇒ Object
374 375 376 |
# File 'lib/tanker.rb', line 374 def type_name tanker_config.[:as] || self.class.name end |
#update_tank_indexes ⇒ Object
update a create instance from index tank
318 319 320 321 322 |
# File 'lib/tanker.rb', line 318 def update_tank_indexes tanker_config.index.add_document( it_doc_id, tanker_index_data, ) end |