Sha256: e790c7937fe06101dd9dff260908b75d4e2bcde5373a966cb925930d73db7137

Contents?: true

Size: 535 Bytes

Versions: 1

Compression:

Stored size: 535 Bytes

Contents

module Adapter
  module Defaults
    def fetch(key, value=nil, &block)
      read(key) || begin
        value = block_given? ? yield(key) : value
        read(key) || value
      end
    end

    def key?(key)
      !read(key).nil?
    end

    def key_for(key)
      if key.is_a?(String)
        key
      elsif key.is_a?(Symbol)
        key.to_s
      else
        Marshal.dump(key)
      end
    end

    def encode(value)
      Marshal.dump(value)
    end

    def decode(value)
      value && Marshal.load(value)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
adapter-0.5.2 lib/adapter/defaults.rb