module AdequateSerialization::CacheBusting
Public Instance Methods
attribute(*names, &block)
click to toggle source
Overrides the previous `attribute` declaration to add some addition validation in the case that we're serializing an ActiveRecord object.
Calls superclass method
# File lib/adequate_serialization/rails/cache_busting.rb, line 104 def attribute(*names, &block) record = serializes if record < ActiveRecord::Base (names.last.is_a?(Hash) ? names[0..-2] : names).each do |attribute| (record.reflect_on_association(attribute) || NullAssociation).setup end end super end
setup()
click to toggle source
# File lib/adequate_serialization/rails/cache_busting.rb, line 53 def setup # If the association is polymorphic, we can't rely on the inverse # to tell us information about cache busting because there are # multiple inverse associations. return if polymorphic? unless inverse_of raise InverseNotFoundError.new(active_record.name, name) end inverse_of.macro == :belongs_to ? setup_belongs_to : setup_has_some end
setup_association_cache(association_name)
click to toggle source
# File lib/adequate_serialization/rails/cache_busting.rb, line 43 def setup_association_cache(association_name) unless defined?(ActiveJob) raise ActiveJobNotFoundError.new(name, association_name) end AdequateSerialization.associate_cache(self, association_name) end
setup_belongs_to()
click to toggle source
Ensures that the `belongs_to` association has the `touch` option enabled in order to bust the parent's cache
# File lib/adequate_serialization/rails/cache_busting.rb, line 70 def setup_belongs_to return if inverse_of.options[:touch] record = active_record.name raise TouchNotFoundError.new(record, klass.name, inverse_of.name) end
setup_has_some()
click to toggle source
Hooks into the serialized class and adds cache busting behavior on commit that will loop through the associated records
# File lib/adequate_serialization/rails/cache_busting.rb, line 79 def setup_has_some klass.setup_association_cache(inverse_of.name) end