Parent

Included Modules

Files

Class/Module Index [+]

Quicksearch

Moneta::Adapters::PStore

PStore backend @api public

Attributes

backend[R]

Public Class Methods

new(options = {}) click to toggle source

@param [Hash] options @option options [String] :file PStore file @option options [::PStore] :backend Use existing backend instance

# File lib/moneta/adapters/pstore.rb, line 17
def initialize(options = {})
  @backend = options[:backend] ||
    begin
      raise ArgumentError, 'Option :file is required' unless options[:file]
      FileUtils.mkpath(::File.dirname(options[:file]))
      new_store(options)
    end
end

Public Instance Methods

clear(options = {}) click to toggle source

(see Proxy#clear)

# File lib/moneta/adapters/pstore.rb, line 68
def clear(options = {})
  @backend.transaction do
    @backend.roots.each do |key|
      @backend.delete(key)
    end
  end
  self
end
create(key, value, options = {}) click to toggle source

(see Proxy#create)

# File lib/moneta/adapters/pstore.rb, line 56
def create(key, value, options = {})
  @backend.transaction do
    if @backend.root?(key)
      false
    else
      @backend[key] = value
      true
    end
  end
end
delete(key, options = {}) click to toggle source

(see Proxy#delete)

# File lib/moneta/adapters/pstore.rb, line 42
def delete(key, options = {})
  @backend.transaction { @backend.delete(key) }
end
increment(key, amount = 1, options = {}) click to toggle source

(see Proxy#increment)

# File lib/moneta/adapters/pstore.rb, line 47
def increment(key, amount = 1, options = {})
  @backend.transaction do
    value = Utils.to_int(@backend[key]) + amount
    @backend[key] = value.to_s
    value
  end
end
key?(key, options = {}) click to toggle source

(see Proxy#key?)

# File lib/moneta/adapters/pstore.rb, line 27
def key?(key, options = {})
  @backend.transaction(true) { @backend.root?(key) }
end
load(key, options = {}) click to toggle source

(see Proxy#load)

# File lib/moneta/adapters/pstore.rb, line 32
def load(key, options = {})
  @backend.transaction(true) { @backend[key] }
end
store(key, value, options = {}) click to toggle source

(see Proxy#store)

# File lib/moneta/adapters/pstore.rb, line 37
def store(key, value, options = {})
  @backend.transaction { @backend[key] = value }
end

Protected Instance Methods

new_store(options) click to toggle source
# File lib/moneta/adapters/pstore.rb, line 79
def new_store(options)
  if RUBY_VERSION > '1.9'
    ::PStore.new(options[:file], options[:threadsafe])
  else
    ::PStore.new(options[:file])
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.