Sha256: 9e1063665fe661f01f5d9a48672b4c97c2c9e401c33f90a77cea734b022dc091

Contents?: true

Size: 779 Bytes

Versions: 2

Compression:

Stored size: 779 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(&: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

2 entries across 2 versions & 1 rubygems

Version Path
cross-stub-0.2.1 lib/cross-stub/cache.rb
cross-stub-0.2.0 lib/cross-stub/cache.rb