Module: Moneta::Defaults

### Home Classes Methods

### In Files

- lib/moneta/mixins.rb

### Namespace

- MODULE Moneta::Defaults::ClassMethods

### Methods

- ::included
- #[]
- #[]=
- #close
- #create
- #decrement
- #features
- #fetch
- #increment
- #key?
- #supports?

### Included Modules

- Moneta::OptionSupport

### Files

- LICENSE

### Class/Module Index

Quicksearch

- Moneta
- Moneta::Adapters
- Moneta::Adapters::ActiveRecord
- Moneta::Adapters::Cassandra
- Moneta::Adapters::Client
- Moneta::Adapters::Cookie
- Moneta::Adapters::Couch
- Moneta::Adapters::DBM
- Moneta::Adapters::DataMapper
- Moneta::Adapters::DataMapper::Store
- Moneta::Adapters::Daybreak
- Moneta::Adapters::File
- Moneta::Adapters::Fog
- Moneta::Adapters::GDBM
- Moneta::Adapters::HBase
- Moneta::Adapters::KyotoCabinet
- Moneta::Adapters::LMDB
- Moneta::Adapters::LRUHash
- Moneta::Adapters::LRUHash::Entry
- Moneta::Adapters::LevelDB
- Moneta::Adapters::LocalMemCache
- Moneta::Adapters::MemcachedDalli
- Moneta::Adapters::MemcachedNative
- Moneta::Adapters::Memory
- Moneta::Adapters::Mongo
- Moneta::Adapters::Null
- Moneta::Adapters::PStore
- Moneta::Adapters::Redis
- Moneta::Adapters::RestClient
- Moneta::Adapters::Riak
- Moneta::Adapters::SDBM
- Moneta::Adapters::Sequel
- Moneta::Adapters::Sqlite
- Moneta::Adapters::TDB
- Moneta::Adapters::TokyoCabinet
- Moneta::Adapters::TokyoTyrant
- Moneta::Adapters::YAML
- Moneta::Builder
- Moneta::Cache
- Moneta::Cache::DSL
- Moneta::CreateSupport
- Moneta::Defaults
- Moneta::Defaults::ClassMethods
- Moneta::Expires
- Moneta::ExpiresSupport
- Moneta::HashAdapter
- Moneta::IncrementSupport
- Moneta::Lock
- Moneta::Logger
- Moneta::Logger::Format
- Moneta::Mutex
- Moneta::OptionMerger
- Moneta::OptionSupport
- Moneta::Pool
- Moneta::Proxy
- Moneta::Semaphore
- Moneta::Server
- Moneta::Shared
- Moneta::Stack
- Moneta::Stack::DSL
- Moneta::SynchronizePrimitive
- Moneta::Transformer
- Moneta::Transformer::Helper
- Moneta::Utils
- Moneta::WeakCreate
- Moneta::WeakIncrement
- Moneta::Wrapper
- Rack
- Rack::Cache
- Rack::Cache::EntityStore
- Rack::Cache::EntityStore::MONETA
- Rack::Cache::EntityStore::Moneta
- Rack::Cache::MetaStore
- Rack::Cache::MetaStore::MONETA
- Rack::Cache::MetaStore::Moneta
- Rack::Cache::MonetaResolver
- Rack::MonetaCookies
- Rack::MonetaRest
- Rack::MonetaStore
- Rack::Session
- Rack::Session::Moneta
- ActionDispatch
- ActionDispatch::Session
- ActionDispatch::Session::MonetaStore
- ActiveSupport
- ActiveSupport::Cache
- ActiveSupport::Cache::MonetaStore

No matching classes.

# Moneta::Defaults

Simple interface to key/value stores with Hash-like interface. @api public

### Public Class Methods

included(base) click to toggle source

    # File lib/moneta/mixins.rb, line 81
    def self.included(base)
      base.extend(ClassMethods)
    end

### Public Instance Methods

[](key) click to toggle source

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

@param [Object] key @return [Object] value @api public

    # File lib/moneta/mixins.rb, line 177
    def [](key)
      load(key)
    end

[]=(key, value) click to toggle source

Store value with key

@param [Object] key @param [Object] value @return value @api public

    # File lib/moneta/mixins.rb, line 187
    def []=(key, value)
      store(key, value)
    end

close() click to toggle source

Explicitly close the store @return nil @api public

    # File lib/moneta/mixins.rb, line 135
    def close
    end

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

Atomically sets a key to value if it's not set.

@note Not every Moneta store implements this method,

    a NotImplementedError is raised if it is not supported.

@param [Object] key @param [Object] value @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}) @return [Boolean] key was set @api public

    # File lib/moneta/mixins.rb, line 203
    def create(key, value, options = {})
      raise NotImplementedError, 'create is not supported'
    end

decrement(key, amount = 1, options = {}) click to toggle source

Atomically decrement integer value with key

This is just syntactic sugar for calling increment with a negative value.

This method also accepts negative amounts.

@param [Object] key @param [Integer] amount @param [Hash] options @option options [String] :prefix Prefix key (See {Transformer}) @option options Other options as defined by the adapters or middleware @return [Object] value from store @api public

    # File lib/moneta/mixins.rb, line 128
    def decrement(key, amount = 1, options = {})
      increment(key, -amount, options)
    end

features() click to toggle source

Returns features list

@return [Array<Symbol>] list of features

    # File lib/moneta/mixins.rb, line 210
    def features
      self.class.features
    end

fetch(key, default = nil, options = nil) click to toggle source

Fetch a value with a key

@overload fetch(key, options = {}, &block)

    retrieve a key. if the key is not available, execute the
    block and return its return value.
    @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})
    @return [Object] value from store

@overload fetch(key, default, options = {})

    retrieve a key. if the key is not available, return the default value.
    @param [Object] key
    @param [Object] default Default value
    @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})
    @return [Object] value from store

@api public

    # File lib/moneta/mixins.rb, line 161
    def fetch(key, default = nil, options = nil)
      if block_given?
        raise ArgumentError, 'Only one argument accepted if block is given' if options
        result = load(key, default || {})
        result == nil ? yield(key) : result
      else
        result = load(key, options || {})
        result == nil ? default : result
      end
    end

increment(key, amount = 1, options = {}) click to toggle source

Atomically increment integer value with key

This method also accepts negative amounts.

@note Not every Moneta store implements this method,

    a NotImplementedError is raised if it is not supported.

@param [Object] key @param [Integer] amount @param [Hash] options @option options [String] :prefix Prefix key (See {Transformer}) @option options Other options as defined by the adapters or middleware @return [Object] value from store @api public

    # File lib/moneta/mixins.rb, line 111
    def increment(key, amount = 1, options = {})
      raise NotImplementedError, 'increment is not supported'
    end

key?(key, options = {}) click to toggle source

Exists the value with key

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

    # File lib/moneta/mixins.rb, line 94
    def key?(key, options = {})
      load(key, options) != nil
    end

supports?(feature) click to toggle source

Return true if adapter supports the given feature.

@return [Boolean]

    # File lib/moneta/mixins.rb, line 217
    def supports?(feature)
      features.include?(feature)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.