Class: Garner::Strategies::Binding::Invalidation::Touch

Inherits:
Base
  • Object
show all
Defined in:
lib/garner/strategies/binding/invalidation/touch.rb

Class Method Summary collapse

Class Method Details

.apply(binding) ⇒ Object

Force-invalidate an object binding. Used when bindings are explicitly invalidated, via binding.invalidate_garner_caches.

Parameters:

  • binding (Object)

    The binding whose caches are to be invalidated.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/garner/strategies/binding/invalidation/touch.rb', line 21

def self.apply(binding)
  if  binding.respond_to?(:destroyed?) &&
      binding.destroyed? &&
      binding.class.respond_to?(:proxy_binding)
    # Binding is destroyed, but we must ensure that its class's
    # proxy_binding is touched, if necessary.
    binding = binding.class.proxy_binding

  elsif binding.respond_to?(:proxy_binding)
    binding = binding.proxy_binding
  end

  binding.touch if binding.respond_to?(:touch)
end

.apply_on_callback?(kind = nil) ⇒ Boolean

Specifies whether invalidation should happen on callbacks.

Parameters:

  • kind (Symbol) (defaults to: nil)

    One of :create, :update, :destroy

Returns:

  • (Boolean)


9
10
11
12
13
14
# File 'lib/garner/strategies/binding/invalidation/touch.rb', line 9

def self.apply_on_callback?(kind = nil)
  # Only apply on destruction, so that class bindings remain
  # valid, if the destroyed binding was not also the previous
  # proxy_binding.
  !!(kind == :destroy)
end