Sha256: 2bb3669a737dda96b72de09ff7d776484dde1e228a8887f978a66a252b85e257

Contents?: true

Size: 470 Bytes

Versions: 1

Compression:

Stored size: 470 Bytes

Contents

module RestrictCache
  module Accessible
    THREAD_KEY = :restrict_cache

    def cache
      Thread.current[THREAD_KEY] ||= Cacheable.new
    end

    def clear
      Thread.current[THREAD_KEY] = nil
    end

    def method_missing(name, *args, &block)
      super unless cache.respond_to?(name)

      define_singleton_method(name) do |*a, &b|
        cache.public_send(name, *a, &b)
      end

      send(name, *args, &block)
    end
  end

  extend Accessible
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
restrict_cache-0.1.1 lib/restrict_cache/accessible.rb