lib/kasket/write_mixin.rb in kasket-4.4.3 vs lib/kasket/write_mixin.rb in kasket-4.4.4
- old
+ new
@@ -1,8 +1,8 @@
+# frozen_string_literal: true
module Kasket
module WriteMixin
-
module ClassMethods
def remove_from_kasket(ids)
Array(ids).each do |id|
Kasket.cache.delete(kasket_key_for_id(id))
end
@@ -36,24 +36,29 @@
key
end
end
def kasket_keys(options = {})
- attribute_sets = [attributes.symbolize_keys]
+ attribute_sets = [attributes]
previous_changes = options[:previous_changes] || previous_changes()
if previous_changes.present?
- old_attributes = Hash[*previous_changes.map { |attribute, values| [attribute, values[0]] }.flatten].symbolize_keys
+ old_attributes = previous_changes.each_with_object({}) do |(attribute, (old, _)), all|
+ all[attribute.to_s] = old
+ end
attribute_sets << old_attributes.reverse_merge(attribute_sets[0])
+ attribute_sets << attribute_sets[0].merge(old_attributes)
end
keys = []
self.class.kasket_indices.each do |index|
- keys += attribute_sets.map do |attribute_set|
- key = self.class.kasket_key_for(index.map { |attribute| [attribute, attribute_set[attribute]]})
- index.include?(:id) ? key : [key, key + '/first']
- end
+ keys.concat(
+ attribute_sets.map do |attribute_set|
+ key = self.class.kasket_key_for(index.map { |attribute| [attribute, attribute_set[attribute.to_s]] })
+ index.include?(:id) ? key : [key, key + '/first']
+ end
+ )
end
keys.flatten!
keys.uniq!
keys
@@ -83,19 +88,21 @@
super
end
if ActiveRecord::VERSION::MAJOR == 3
def update_column(column, value)
- previous_changes = {column => [attributes[column.to_s], value]}
+ previous_changes = { column => [attributes[column.to_s], value] }
result = super
clear_kasket_indices(previous_changes: previous_changes)
result
end
else
def update_columns(new_attributes)
previous_attributes = attributes
- previous_changes = new_attributes.each_with_object({}) { |(k, v), all| all[k] = [previous_attributes[k.to_s], v] }
+ previous_changes = new_attributes.each_with_object({}) do |(k, v), all|
+ all[k] = [previous_attributes[k.to_s], v]
+ end
result = super
clear_kasket_indices(previous_changes: previous_changes)
result
end
end
@@ -107,10 +114,10 @@
def kasket_after_save
Kasket.add_pending_record(self)
end
def kasket_after_destroy
- Kasket.add_pending_record(self, destroyed = true)
+ Kasket.add_pending_record(self, _destroyed = true)
end
def committed!(*)
Kasket.clear_pending_records
kasket_after_commit if persisted? || destroyed?