Class: Elasticsearch::Model::Extensions::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/elasticsearch/model/extensions/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(active_record_class, parent_class: parent_class, delayed:, only_if: -> r { true }, records_to_update_documents: nil, field_to_update: nil, block: nil) ⇒ Configuration

Returns a new instance of Configuration.



9
10
11
12
13
14
15
16
17
18
# File 'lib/elasticsearch/model/extensions/configuration.rb', line 9

def initialize(active_record_class, parent_class: parent_class, delayed:, only_if: -> r { true }, records_to_update_documents: nil, field_to_update: nil, block: nil)
  @delayed = @delayed

  @active_record_class = active_record_class
  @parent_class = parent_class
  @if = binding.local_variable_get(:only_if)
  @records_to_update_documents = records_to_update_documents
  @field_to_update = field_to_update
  @block = block
end

Instance Attribute Details

#delayedObject (readonly)

Returns the value of attribute delayed.



7
8
9
# File 'lib/elasticsearch/model/extensions/configuration.rb', line 7

def delayed
  @delayed
end

Instance Method Details

#blockObject



40
41
42
# File 'lib/elasticsearch/model/extensions/configuration.rb', line 40

def block
  to_hash[:block]
end

#field_to_updateObject



24
25
26
# File 'lib/elasticsearch/model/extensions/configuration.rb', line 24

def field_to_update
  to_hash[:field_to_update]
end

#has_dependent_fields?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/elasticsearch/model/extensions/configuration.rb', line 51

def has_dependent_fields?
  @has_dependent_fields
end

#index_update_required?(record) ⇒ Boolean

whether it must be also updated in elasticsearch or not

Parameters:

  • record (ActiveRecord::Base)

    the updated record we are unsure

Returns:

  • (Boolean)

    true if we have to update the document for the record indexed in Elasticsearch



58
59
60
61
62
63
64
# File 'lib/elasticsearch/model/extensions/configuration.rb', line 58

def index_update_required?(record)
  previous_changes = record.previous_changes

  defined?(record.index_update_required?) && record.index_update_required? ||
    (previous_changes.keys & nested_object_fields).size > 0 ||
    (previous_changes.size > 0 && has_dependent_fields?)
end

#nested_object_fieldsArray

TODO Document what is in the Array

Returns:

  • (Array)


46
47
48
# File 'lib/elasticsearch/model/extensions/configuration.rb', line 46

def nested_object_fields
  @nested_object_fields
end

#only_ifObject



28
29
30
# File 'lib/elasticsearch/model/extensions/configuration.rb', line 28

def only_if
  to_hash[:only_if]
end

#optionally_delayedObject



36
37
38
# File 'lib/elasticsearch/model/extensions/configuration.rb', line 36

def optionally_delayed
  -> t { delayed ? t.delay : t }
end

#records_to_update_documentsObject



32
33
34
# File 'lib/elasticsearch/model/extensions/configuration.rb', line 32

def records_to_update_documents
  to_hash[:records_to_update_documents]
end

#to_hashObject



20
21
22
# File 'lib/elasticsearch/model/extensions/configuration.rb', line 20

def to_hash
  @cached_hash ||= build_hash
end