Class: Moneta::Adapters::DataMapper

### Home Classes Methods

### In Files

- lib/moneta/adapters/datamapper.rb

### Parent

Object

### Namespace

- CLASS Moneta::Adapters::DataMapper::Store

### Methods

- ::new
- #clear
- #create
- #delete
- #key?
- #load
- #store

### Included Modules

- Moneta::Defaults

### 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::Adapters::DataMapper

Datamapper backend @api public

### Public Class Methods

new(options = {}) click to toggle source

@param [Hash] options @option options [String] :setup Datamapper setup string @option options [String/Symbol] :repository (:moneta) Repository name @option options [String/Symbol] :table (:moneta) Table name

    # File lib/moneta/adapters/datamapper.rb, line 24
    def initialize(options = {})
      raise ArgumentError, 'Option :setup is required' unless options[:setup]
      @repository = (options.delete(:repository) || :moneta).to_sym
      Store.storage_names[@repository] = (options.delete(:table) || :moneta).to_s
      ::DataMapper.setup(@repository, options[:setup])
      context { Store.auto_upgrade! }
    end

### Public Instance Methods

clear(options = {}) click to toggle source

(see Proxy#clear)

    # File lib/moneta/adapters/datamapper.rb, line 84
    def clear(options = {})
      context { Store.all.destroy! }
      self
    end

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

(see Proxy#create)

    # File lib/moneta/adapters/datamapper.rb, line 61
    def create(key, value, options = {})
      context do
        Store.create(:k => key, :v => value)
        true
      end
    rescue
      # FIXME: This catches too many errors
      # it should only catch a not-unique-exception
      false
    end

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

(see Proxy#delete)

    # File lib/moneta/adapters/datamapper.rb, line 73
    def delete(key, options = {})
      context do
        if record = Store.get(key)
          value = record.v
          record.destroy!
          value
        end
      end
    end

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

(see Proxy#key?)

    # File lib/moneta/adapters/datamapper.rb, line 33
    def key?(key, options = {})
      context { Store.get(key) != nil }
    end

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

(see Proxy#load)

    # File lib/moneta/adapters/datamapper.rb, line 38
    def load(key, options = {})
      context do
        record = Store.get(key)
        record && record.v
      end
    end

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

(see Proxy#store)

    # File lib/moneta/adapters/datamapper.rb, line 46
    def store(key, value, options = {})
      context do
        if record = Store.get(key)
          record.update(:k => key, :v => value)
        else
          Store.create(:k => key, :v => value)
        end
        value
      end
    rescue
      tries ||= 0
      (tries += 1) < 10 ? retry : raise
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.