Class: Elasticsearch::Model::Extensions::Configuration
- Inherits:
-
Object
- Object
- Elasticsearch::Model::Extensions::Configuration
- Defined in:
- lib/elasticsearch/model/extensions/configuration.rb
Instance Attribute Summary collapse
-
#delayed ⇒ Object
readonly
Returns the value of attribute delayed.
Instance Method Summary collapse
- #block ⇒ Object
- #field_to_update ⇒ Object
- #has_dependent_fields? ⇒ Boolean
-
#index_update_required?(record) ⇒ Boolean
whether it must be also updated in elasticsearch or not.
-
#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
constructor
A new instance of Configuration.
-
#nested_object_fields ⇒ Array
TODO Document what is in the Array.
- #only_if ⇒ Object
- #optionally_delayed ⇒ Object
- #records_to_update_documents ⇒ Object
- #to_hash ⇒ Object
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
#delayed ⇒ Object (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
#block ⇒ Object
40 41 42 |
# File 'lib/elasticsearch/model/extensions/configuration.rb', line 40 def block to_hash[:block] end |
#field_to_update ⇒ Object
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
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
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_fields ⇒ Array
TODO Document what is in the Array
46 47 48 |
# File 'lib/elasticsearch/model/extensions/configuration.rb', line 46 def nested_object_fields @nested_object_fields end |
#only_if ⇒ Object
28 29 30 |
# File 'lib/elasticsearch/model/extensions/configuration.rb', line 28 def only_if to_hash[:only_if] end |
#optionally_delayed ⇒ Object
36 37 38 |
# File 'lib/elasticsearch/model/extensions/configuration.rb', line 36 def optionally_delayed -> t { delayed ? t.delay : t } end |
#records_to_update_documents ⇒ Object
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_hash ⇒ Object
20 21 22 |
# File 'lib/elasticsearch/model/extensions/configuration.rb', line 20 def to_hash @cached_hash ||= build_hash end |