Class: Elasticated::BulkActions::IndexAction

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

Direct Known Subclasses

CreateAction

Instance Attribute Summary collapse

Attributes inherited from StandardAction

#repository

Instance Method Summary collapse

Constructor Details

#initialize(repository, document, params = {}) ⇒ IndexAction

Returns a new instance of IndexAction.



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

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

Instance Attribute Details

#documentObject

Returns the value of attribute document.



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

def document
  @document
end

#paramsObject

Returns the value of attribute params.



5
6
7
# File 'lib/elasticated/bulk_actions/index_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
# File 'lib/elasticated/bulk_actions/index_action.rb', line 13

def build
  original_params = Helpers.hash_deep_dup params
  # preparations
  prepared_document = repository.prepare_document document
  prepared_params = repository.params_for_document document, original_params
  # the final command
  prepared_params[:_index] = prepared_params.delete(:index) || prepared_document.index || raise("An index name is required for a document indexation")
  prepared_params[:_type] = prepared_params.delete(:type) || prepared_document.type || raise("A type name is required for a document indexation")
  prepared_params[:_id] = prepared_params.delete(:id) || prepared_document.id
  command = { command_name => prepared_params }
  prepared_source = prepared_document.source
  [command, prepared_source]
end