Class: Chewy::Index::Specification
- Defined in:
- lib/chewy/index/specification.rb
Overview
Index specification is a combination of index settings and
mappings. The idea behind this class is that specification
can be locked in the Chewy::Stash::Specification
between
resets, so it is possible to track changes. In the future
it is planned to be way smarter but right now rake chewy:deploy
checks if there were changes and resets the index only if
anything was changed. Otherwise, the index reset is skipped.
Instance Method Summary collapse
-
#changed? ⇒ true, false
Compares previously locked and current specifications.
-
#current ⇒ Hash
Simply returns
Chewy::Index.specification_hash
, but prepared for JSON withas_json
method. -
#initialize(index) ⇒ Specification
constructor
A new instance of Specification.
-
#lock! ⇒ true
Stores the current index specification to the
Chewy::Stash::Specification
as json. -
#locked ⇒ Hash
Returns the last locked specification as ruby hash.
Constructor Details
#initialize(index) ⇒ Specification
Returns a new instance of Specification.
15 16 17 |
# File 'lib/chewy/index/specification.rb', line 15 def initialize(index) @index = index end |
Instance Method Details
#changed? ⇒ true, false
Compares previously locked and current specifications.
55 56 57 |
# File 'lib/chewy/index/specification.rb', line 55 def changed? current != locked end |
#current ⇒ Hash
Simply returns Chewy::Index.specification_hash
, but
prepared for JSON with as_json
method. This means all the
keys are strings and there are only values of types handled in JSON.
48 49 50 |
# File 'lib/chewy/index/specification.rb', line 48 def current @index.specification_hash.as_json end |
#lock! ⇒ true
Stores the current index specification to the Chewy::Stash::Specification
as json.
24 25 26 27 28 29 |
# File 'lib/chewy/index/specification.rb', line 24 def lock! Chewy::Stash::Specification.import!([ id: @index.derivable_name, specification: Base64.encode64(current.to_json) ], journal: false) end |
#locked ⇒ Hash
Returns the last locked specification as ruby hash. Returns empty hash if nothing is stored yet.
35 36 37 38 39 40 |
# File 'lib/chewy/index/specification.rb', line 35 def locked filter = {ids: {values: [@index.derivable_name]}} document = Chewy::Stash::Specification.filter(filter).first return {} unless document JSON.load(Base64.decode64(document.specification)) # rubocop:disable Security/JSONLoad end |