Sha256: 66e6ce88d2b8e1e97c39c00eb0728d3346fad036adbf115e8ea2d923636baa9b

Contents?: true

Size: 797 Bytes

Versions: 2

Compression:

Stored size: 797 Bytes

Contents

# frozen_string_literal: true
module IdentityCache
  class ExpiryHook
    def initialize(cached_association)
      @cached_association = cached_association
    end

    def install
      cached_association.validate
      entry = [parent_class, only_on_foreign_key_change?]
      child_class.parent_expiration_entries[inverse_name] << entry
    end

    private

    attr_reader :cached_association

    def only_on_foreign_key_change?
      cached_association.embedded_by_reference? && !cached_association.reflection.has_scope?
    end

    def inverse_name
      cached_association.inverse_name
    end

    def parent_class
      cached_association.reflection.active_record
    end

    def child_class
      cached_association.reflection.klass
    end
  end

  private_constant :ExpiryHook
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
identity_cache-1.1.0 lib/identity_cache/expiry_hook.rb
identity_cache-1.0.1 lib/identity_cache/expiry_hook.rb