Class: Moneta::Adapters::Daybreak

Inherits:
Memory
  • Object
show all
Defined in:
lib/moneta/adapters/daybreak.rb

Overview

Daybreak backend

Instance Method Summary collapse

Methods included from HashAdapter

#clear, #delete, #key?, #load, #store

Methods included from Defaults

#[], #[]=, #decrement, #fetch, #key?

Methods included from OptionSupport

#expires, #prefix, #raw, #with

Constructor Details

#initialize(options = {}) ⇒ Daybreak

Returns a new instance of Daybreak

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :file (String)

    Database file

Raises:

  • (ArgumentError)

10
11
12
13
# File 'lib/moneta/adapters/daybreak.rb', line 10

def initialize(options = {})
  raise ArgumentError, 'Option :file is required' unless options[:file]
  @hash = ::Daybreak::DB.new(options[:file], :serializer => ::Daybreak::Serializer::None)
end

Instance Method Details

#closeObject

Explicitly close the store

Returns:

  • nil


21
22
23
# File 'lib/moneta/adapters/daybreak.rb', line 21

def close
  @hash.close
end

#increment(key, amount = 1, options = {}) ⇒ Object

Note:

Not every Moneta store implements this method, a NotImplementedError is raised if it is not supported.

Atomically increment integer value with key

This method also accepts negative amounts.

Parameters:

  • key (Object)
  • amount (Integer) (defaults to: 1)
  • options (Hash) (defaults to: {})

Returns:

  • (Object)

    value from store


16
17
18
# File 'lib/moneta/adapters/daybreak.rb', line 16

def increment(key, amount = 1, options = {})
  @hash.lock { return super }
end