Module: Kasket::ReloadAssociationMixin

Defined in:
lib/kasket/reload_association_mixin.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



16
17
18
# File 'lib/kasket/reload_association_mixin.rb', line 16

def self.included(base)
  base.alias_method_chain :reload, :kasket_clearing
end

Instance Method Details

#reload_with_kasket_clearing(*args) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/kasket/reload_association_mixin.rb', line 4

def reload_with_kasket_clearing(*args)
  if loaded?
    Kasket.clear_local if target.class.include?(WriteMixin)
  else
    refl = (ActiveRecord::VERSION::MAJOR == 2 || AR30) ? proxy_reflection : reflection
    target_class = (refl.options[:polymorphic] ? (respond_to?(:klass) ? klass : association_class) : refl.klass)
    Kasket.clear_local if target_class && target_class.include?(WriteMixin)
  end

  reload_without_kasket_clearing(*args)
end