Class: Chewy::Stash::Journal
Class Method Summary collapse
-
.clean(until_time = nil, only: []) ⇒ Object
Cleans up all the journal entries until the specified time.
-
.entries(since_time, only: []) ⇒ Object
Loads all entries since the specified time.
-
.for(*something) ⇒ Object
Selects all the journal entries for the specified indices.
Methods inherited from Index
base_name, build_index_name, define_type, derivable_index_name, derivable_name, index_name, index_params, mappings_hash, method_missing, prefix, prefix_with_deprecation, scopes, settings, settings_hash, specification, specification_hash, type, type_names, types
Class Method Details
.clean(until_time = nil, only: []) ⇒ Object
Cleans up all the journal entries until the specified time. If nothing is specified - cleans up everything.
35 36 37 38 39 |
# File 'lib/chewy/stash.rb', line 35 def self.clean(until_time = nil, only: []) scope = self.for(only) scope = scope.filter(range: {created_at: {lte: until_time}}) if until_time scope.delete_all end |
.entries(since_time, only: []) ⇒ Object
Loads all entries since the specified time.
26 27 28 |
# File 'lib/chewy/stash.rb', line 26 def self.entries(since_time, only: []) self.for(only).filter(range: {created_at: {gt: since_time}}) end |
.for(*something) ⇒ Object
Selects all the journal entries for the specified indices.
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/chewy/stash.rb', line 44 def self.for(*something) something = something.flatten.compact types = something.flat_map { |s| Chewy.derive_types(s) } return none if something.present? && types.blank? scope = all types.group_by(&:index).each do |index, index_types| scope = scope.or( filter(term: {index_name: index.derivable_name}) .filter(terms: {type_name: index_types.map(&:type_name)}) ) end scope end |