module Cacheable::CacheAdapter

Constants

CACHE_ADAPTER_METHODS
DEFAULT_ADAPTER

Public Class Methods

extended(base) click to toggle source
# File lib/cacheable/cache_adapter.rb, line 8
def self.extended(base)
  base.instance_variable_set(:@_cache_adapter, nil)
  base.cache_adapter = DEFAULT_ADAPTER
end

Public Instance Methods

cache_adapter() click to toggle source
# File lib/cacheable/cache_adapter.rb, line 13
def cache_adapter
  @_cache_adapter
end
cache_adapter=(name_or_adapter) click to toggle source
# File lib/cacheable/cache_adapter.rb, line 17
def cache_adapter=(name_or_adapter)
  @_cache_adapter = interpret_adapter(name_or_adapter)
end

Private Instance Methods

cache_adapter?(adapter_instance) click to toggle source
# File lib/cacheable/cache_adapter.rb, line 33
def cache_adapter?(adapter_instance)
  CACHE_ADAPTER_METHODS.all? { |method| adapter_instance.respond_to?(method) }
end
interpret_adapter(name_or_adapter) click to toggle source
# File lib/cacheable/cache_adapter.rb, line 23
def interpret_adapter(name_or_adapter)
  return name_or_adapter if cache_adapter?(name_or_adapter)

  unless [Symbol, String].include?(name_or_adapter.class)
    raise ArgumentError, 'Must pass the name of a known adapter or an instance'
  end

  Cacheable::CacheAdapters.lookup(name_or_adapter).new
end