Module: Kasket::WriteMixin::InstanceMethods
- Defined in:
- lib/kasket/write_mixin.rb
Instance Method Summary collapse
- #clear_kasket_indices ⇒ Object
- #default_kasket_cacheable? ⇒ Boolean
- #kasket_key ⇒ Object
- #kasket_keys ⇒ Object
- #reload_with_kasket_clearing(*args) ⇒ Object
- #store_in_kasket ⇒ Object
Instance Method Details
#clear_kasket_indices ⇒ Object
60 61 62 63 64 |
# File 'lib/kasket/write_mixin.rb', line 60 def clear_kasket_indices kasket_keys.each do |key| Kasket.cache.delete(key) end end |
#default_kasket_cacheable? ⇒ Boolean
29 30 31 |
# File 'lib/kasket/write_mixin.rb', line 29 def default_kasket_cacheable? true end |
#kasket_key ⇒ Object
25 26 27 |
# File 'lib/kasket/write_mixin.rb', line 25 def kasket_key @kasket_key ||= new_record? ? nil : self.class.kasket_key_for_id(id) end |
#kasket_keys ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/kasket/write_mixin.rb', line 39 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
66 67 68 69 |
# File 'lib/kasket/write_mixin.rb', line 66 def reload_with_kasket_clearing(*args) Kasket.clear_local reload_without_kasket_clearing(*args) end |