Module: Kasket::WriteMixin::InstanceMethods
- Defined in:
- lib/kasket/write_mixin.rb
Instance Method Summary collapse
- #clear_kasket_indices ⇒ Object
- #clear_local_kasket_indices ⇒ Object
- #kasket_key ⇒ Object
- #kasket_keys ⇒ Object
- #reload_with_kasket_clearing(*args) ⇒ Object
- #store_in_kasket ⇒ Object
Instance Method Details
#clear_kasket_indices ⇒ Object
49 50 51 52 53 |
# File 'lib/kasket/write_mixin.rb', line 49 def clear_kasket_indices kasket_keys.each do |key| Kasket.cache.delete(key) end end |
#clear_local_kasket_indices ⇒ Object
55 56 57 58 59 |
# File 'lib/kasket/write_mixin.rb', line 55 def clear_local_kasket_indices kasket_keys.each do |key| Kasket.cache.delete_local(key) end end |
#kasket_key ⇒ Object
18 19 20 |
# File 'lib/kasket/write_mixin.rb', line 18 def kasket_key @kasket_key ||= new_record? ? nil : self.class.kasket_key_for_id(id) end |
#kasket_keys ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/kasket/write_mixin.rb', line 28 def kasket_keys attribute_sets = [attributes.symbolize_keys] if changed? old_attributes = Hash[*changes.map {|attribute, values| [attribute, values[0]]}.flatten].symbolize_keys attribute_sets << old_attributes.reverse_merge(attribute_sets[0]) 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 end keys.flatten! keys.uniq! keys end |
#reload_with_kasket_clearing(*args) ⇒ Object
61 62 63 64 |
# File 'lib/kasket/write_mixin.rb', line 61 def reload_with_kasket_clearing(*args) clear_local_kasket_indices reload_without_kasket_clearing(*args) end |