class Moneta::Proxy

Proxy base class @api public

Attributes

adapter[R]

Public Class Methods

features_mask() click to toggle source

@api private

# File lib/moneta/proxy.rb, line 128
def features_mask
  @features_mask ||= [].freeze
end
new(adapter, options = {}) click to toggle source

@param [Moneta store] adapter underlying adapter @param [Hash] options

# File lib/moneta/proxy.rb, line 12
def initialize(adapter, options = {})
  @adapter = adapter
  configure(**options)
end
not_supports(*features) click to toggle source

(see Defaults::ClassMethods#not_supports)

Calls superclass method
# File lib/moneta/proxy.rb, line 133
def not_supports(*features)
  @features_mask = (features_mask | features).freeze
  super
end

Public Instance Methods

clear(options = {}) click to toggle source

Clear all keys in this store

@param [Hash] options @return [void] @api public

# File lib/moneta/proxy.rb, line 95
def clear(options = {})
  adapter.clear(options)
  self
end
close() click to toggle source

(see Defaults#close)

# File lib/moneta/proxy.rb, line 43
def close
  adapter.close
end
config() click to toggle source

Overrides the default implementation of the config method to:

  • pass the adapter’s config, if this proxy has no configuration of its own

  • return a merged configuration, allowing the proxy have precedence over the adapter

Calls superclass method Moneta::Config#config
# File lib/moneta/proxy.rb, line 145
def config
  unless @proxy_config
    config = super
    adapter_config = adapter.config if adapter.class.include?(Config)

    @proxy_config =
      if config && adapter_config
        adapter_members = adapter_config.members - config.members
        members = config.members + adapter_members
        struct = Struct.new(*members)

        values = config.values + adapter_config.to_h.values_at(*adapter_members)
        struct.new(*values)
      else
        config || adapter_config
      end
  end

  @proxy_config
end
create(key, value, options = {}) click to toggle source

(see Defaults#create)

# File lib/moneta/proxy.rb, line 38
def create(key, value, options = {})
  adapter.create(key, value, options)
end
delete(key, options = {}) click to toggle source

Delete the key from the store and return the current value

@param [Object] key @return [Object] current value @param [Hash] options @option options [Boolean] :raw Raw access without value transformation (See {Transformer}) @option options [String] :prefix Prefix key (See {Transformer}) @option options Other options as defined by the adapters or middleware @api public

# File lib/moneta/proxy.rb, line 86
def delete(key, options = {})
  adapter.delete(key, options)
end
each_key(&block) click to toggle source

(see Defaults#each_key)

# File lib/moneta/proxy.rb, line 23
def each_key(&block)
  raise NotImplementedError, "each_key is not supported on this proxy" \
    unless supports? :each_key

  return enum_for(:each_key) { adapter.each_key.size } unless block_given?
  adapter.each_key(&block)
  self
end
features() click to toggle source

(see Defaults#features)

# File lib/moneta/proxy.rb, line 122
def features
  @features ||= (self.class.features | adapter.features - self.class.features_mask).freeze
end
fetch_values(*keys, **options, &defaults) click to toggle source

(see Defaults#fetch_values)

# File lib/moneta/proxy.rb, line 106
def fetch_values(*keys, **options, &defaults)
  adapter.fetch_values(*keys, **options, &defaults)
end
increment(key, amount = 1, options = {}) click to toggle source

(see Defaults#increment)

# File lib/moneta/proxy.rb, line 33
def increment(key, amount = 1, options = {})
  adapter.increment(key, amount, options)
end
key?(key, options = {}) click to toggle source

(see Defaults#key?)

# File lib/moneta/proxy.rb, line 18
def key?(key, options = {})
  adapter.key?(key, options)
end
load(key, options = {}) click to toggle source

Fetch value with key. Return nil if the key doesn’t exist

@param [Object] key @param [Hash] options @option options [Integer] :expires Update expiration time (See {Expires}) @option options [Boolean] :raw Raw access without value transformation (See {Transformer}) @option options [String] :prefix Prefix key (See {Transformer}) @option options [Boolean] :sync Synchronized load ({Cache} reloads from adapter, {Adapters::Daybreak} syncs with file) @option options Other options as defined by the adapters or middleware @return [Object] value @api public

# File lib/moneta/proxy.rb, line 58
def load(key, options = {})
  adapter.load(key, options)
end
merge!(pairs, options = {}, &block) click to toggle source

(see Defaults#merge!)

# File lib/moneta/proxy.rb, line 116
def merge!(pairs, options = {}, &block)
  adapter.merge!(pairs, options, &block)
  self
end
slice(*keys, **options) click to toggle source

(see Defaults#slice)

# File lib/moneta/proxy.rb, line 111
def slice(*keys, **options)
  adapter.slice(*keys, **options)
end
store(key, value, options = {}) click to toggle source

Store value with key

@param [Object] key @param [Object] value @param [Hash] options @option options [Integer] :expires Set expiration time (See {Expires}) @option options [Boolean] :raw Raw access without value transformation (See {Transformer}) @option options [String] :prefix Prefix key (See {Transformer}) @option options Other options as defined by the adapters or middleware @return value @api public

# File lib/moneta/proxy.rb, line 73
def store(key, value, options = {})
  adapter.store(key, value, options)
end
values_at(*keys, **options) click to toggle source

(see Defaults#values_at)

# File lib/moneta/proxy.rb, line 101
def values_at(*keys, **options)
  adapter.values_at(*keys, **options)
end