Sha256: bbb91e48132ea44c656bcd71800da07c970881941c6ac5d302220dd3858f0169

Contents?: true

Size: 568 Bytes

Versions: 2

Compression:

Stored size: 568 Bytes

Contents

module Caching
  class Proxy
  
    instance_methods.each { |m| undef_method m unless m =~ /(^__|^send$|^object_id$)/ }

    def initialize(target, *methods)
      @target = target
      @methods = methods.map(&:to_sym)
      @storage = Storage.new
    end

    def method_missing(method, *args, &block)
      if @methods.include? method.to_sym
        @storage.fetch(method) { @target.send(method, *args, &block) }
      else
        @target.send(method, *args, &block)
      end
    end

    def clear_cache(*methods)
      @storage.clear *methods
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
caching-0.0.2 lib/caching/proxy.rb
caching-0.0.1 lib/caching/proxy.rb