Class: Searchkick::RecordData

Inherits:
Object
  • Object
show all
Defined in:
lib/searchkick/record_data.rb

Constant Summary collapse

EXCLUDED_ATTRIBUTES =
["id", :id]
TYPE_KEYS =
["type", :type]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(index, record) ⇒ RecordData



8
9
10
11
# File 'lib/searchkick/record_data.rb', line 8

def initialize(index, record)
  @index = index
  @record = record
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



6
7
8
# File 'lib/searchkick/record_data.rb', line 6

def index
  @index
end

#recordObject (readonly)

Returns the value of attribute record.



6
7
8
# File 'lib/searchkick/record_data.rb', line 6

def record
  @record
end

Instance Method Details

#delete_dataObject



25
26
27
# File 'lib/searchkick/record_data.rb', line 25

def delete_data
  {delete: record_data}
end

#document_type(ignore_type = false) ⇒ Object



34
35
36
# File 'lib/searchkick/record_data.rb', line 34

def document_type(ignore_type = false)
  index.klass_document_type(record.class, ignore_type)
end

#index_dataObject



13
14
15
16
17
# File 'lib/searchkick/record_data.rb', line 13

def index_data
  data = record_data
  data[:data] = search_data
  {index: data}
end

#search_idObject



29
30
31
32
# File 'lib/searchkick/record_data.rb', line 29

def search_id
  id = record.respond_to?(:search_document_id) ? record.search_document_id : record.id
  id.is_a?(Numeric) ? id : id.to_s
end

#update_data(method_name) ⇒ Object



19
20
21
22
23
# File 'lib/searchkick/record_data.rb', line 19

def update_data(method_name)
  data = record_data
  data[:data] = {doc: search_data(method_name)}
  {update: data}
end