Class: Elasticated::BulkActions::DeleteAction

Inherits:
StandardAction show all
Defined in:
lib/elasticated/bulk_actions/delete_action.rb

Instance Attribute Summary collapse

Attributes inherited from StandardAction

#repository

Instance Method Summary collapse

Constructor Details

#initialize(repository, document_id, params = {}) ⇒ DeleteAction

Returns a new instance of DeleteAction.



7
8
9
10
11
# File 'lib/elasticated/bulk_actions/delete_action.rb', line 7

def initialize(repository, document_id, params={})
  super repository
  self.document_id = document_id
  self.params = params
end

Instance Attribute Details

#document_idObject

Returns the value of attribute document_id.



5
6
7
# File 'lib/elasticated/bulk_actions/delete_action.rb', line 5

def document_id
  @document_id
end

#paramsObject

Returns the value of attribute params.



5
6
7
# File 'lib/elasticated/bulk_actions/delete_action.rb', line 5

def params
  @params
end

Instance Method Details

#buildObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/elasticated/bulk_actions/delete_action.rb', line 13

def build
  original_params = Helpers.hash_deep_dup params
  # preparations
  prepared_params = repository.params_for_ids [document_id], original_params
  # verifications
  prepared_params[:index] || raise("A target index should be specified in a delete")
  prepared_params[:type] || raise("A target type should be specified in a delete")
  # the final command
  prepared_params[:_index] = prepared_params.delete :index
  prepared_params[:_type] = prepared_params.delete :type
  prepared_params[:_id] = document_id
  command = { delete: prepared_params }
  [command]
end