Class: IndexTanked::ActiveRecordDefaults::InstanceCompanion
Constant Summary
collapse
- MissingAttributeError =
ActiveModel::MissingAttributeError
Instance Method Summary
collapse
#api_client, #doc_id, #index, #initialize
Instance Method Details
#created_at ⇒ Object
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
|
#data ⇒ Object
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
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_addition ⇒ Object
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
|