Class: IndexTanked::ActiveRecordDefaults::InstanceCompanion

Inherits:
InstanceCompanion show all
Defined in:
lib/index-tanked/active_record_defaults/instance_companion.rb

Constant Summary collapse

MissingAttributeError =
ActiveModel::MissingAttributeError

Instance Method Summary collapse

Methods inherited from InstanceCompanion

#api_client, #doc_id, #index, #initialize

Constructor Details

This class inherits a constructor from IndexTanked::InstanceCompanion

Instance Method Details

#created_atObject



10
11
12
13
14
15
16
# File 'lib/index-tanked/active_record_defaults/instance_companion.rb', line 10

def created_at
  if @companion.respond_to?(:created_at)
    @companion.created_at
  else
    Time.now
  end
end

#dataObject



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/index-tanked/active_record_defaults/instance_companion.rb', line 18

def data
  begin
    field_data, other_data = *super
    field_data.merge!(:timestamp => created_at.to_i, :model => @companion.class.name)
  rescue MissingAttributeError
    @companion.reload
    field_data, other_data = *super
    field_data.merge!(:timestamp => created_at.to_i, :model => @companion.class.name)
  end
  [field_data, other_data]
end

#dependencies_changed?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/index-tanked/active_record_defaults/instance_companion.rb', line 30

def dependencies_changed?
  @companion.class.index_tanked.dependent_fields.any?{|field| @companion.send("#{field}_changed?") }
end

#document_for_batch_additionObject



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/index-tanked/active_record_defaults/instance_companion.rb', line 34

def document_for_batch_addition
  ancestor = @companion.class._ancestors_to_index.first
  if ancestor
    documents = []
    documents << super
    documents << @companion.becomes(ancestor).index_tanked.document_for_batch_addition if ancestor
    documents.flatten.compact
  else
    super
  end
end