Sha256: d9e205c5ba4db45ba2e12373e4e228bfd7a5591c2c55def8049c4ae219474141

Contents?: true

Size: 752 Bytes

Versions: 1

Compression:

Stored size: 752 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?
    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

1 entries across 1 versions & 1 rubygems

Version Path
identity_cache-1.0.0 lib/identity_cache/expiry_hook.rb