Class: Elasticated::BulkActions::UpdateAction

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

Direct Known Subclasses

UpsertAction

Instance Attribute Summary collapse

Attributes inherited from StandardAction

#repository

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of UpdateAction.



7
8
9
10
11
# File 'lib/elasticated/bulk_actions/update_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/update_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/update_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
27
28
29
30
# File 'lib/elasticated/bulk_actions/update_action.rb', line 13

def build
  original_params = Helpers.hash_deep_dup params
  # verifications
  source = original_params.delete(:source) || raise("No body specified for partial update")
  # preparations
  prepared_source = repository.prepare_source Helpers.hash_deep_dup source
  prepared_params = repository.params_for_source source, original_params
  # more verifications
  prepared_params[:index] || raise("A target index should be specified in a partial update")
  prepared_params[:type] || raise("A target type should be specified in a partial update")
  # the final command
  prepared_params[:_index] = prepared_params.delete :index
  prepared_params[:_type] = prepared_params.delete :type
  prepared_params[:_id] = document_id
  command = { command_name => prepared_params }
  body = build_body_from prepared_source
  [command, body]
end