Sha256: 784032bb2781f43502f109c1d732731f01a88fae14b8d1babd728f15b83a3846

Contents?: true

Size: 784 Bytes

Versions: 3

Compression:

Stored size: 784 Bytes

Contents

module CrossStub

  class UnsupportedCacheStore < Exception ; end

  module Cache
    class << self

      extend Forwardable
      def_delegator :@store, :clear
      def_delegator :@store, :get
      def_delegator :@store, :set

      def setup(opts)
        init(opts, true)
      end

      def refresh(opts)
        init(opts, false)
      end

      private

        def init(opts, truncate)
          type, arg = opts.to_a[0].map{|o| o.to_s }
          @store =
            begin
              store_name = '%s%s' % [type[0..0].upcase, type[1..-1].downcase]
              Stores.const_get(store_name).new(arg, truncate)
            rescue
              raise UnsupportedCacheStore.new('Store type :%s is not supported !!' % type)
            end
        end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cross-stub-0.2.4 lib/cross-stub/cache.rb
cross-stub-0.2.3 lib/cross-stub/cache.rb
cross-stub-0.2.2 lib/cross-stub/cache.rb