Class: Medusa::Storage::Moneta

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/medusa/storage/moneta.rb

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ Moneta

Returns a new instance of Moneta.



13
14
15
16
# File 'lib/medusa/storage/moneta.rb', line 13

def initialize(name, options = {})
  default_options = { threadsafe: true, prefix: 'medusa' }
  @moneta = ::Moneta.new(name, default_options.merge(options))
end

Instance Method Details

#eachObject



18
19
20
21
22
23
# File 'lib/medusa/storage/moneta.rb', line 18

def each
  @moneta.each_key do |k|
    yield k, @moneta.fetch(k)
  end
  self
end

#keysObject



32
33
34
# File 'lib/medusa/storage/moneta.rb', line 32

def keys
  @moneta.each_key.to_a.sort
end

#merge!(hash) ⇒ Object



36
37
38
39
# File 'lib/medusa/storage/moneta.rb', line 36

def merge!(hash)
  @moneta.merge!(hash) unless hash.empty?
  self
end

#sizeObject



25
26
27
28
29
30
# File 'lib/medusa/storage/moneta.rb', line 25

def size
  current_size = @moneta.each_key.size

  return @moneta.each_key.reduce(0) { |size, k|  size + 1 } if current_size.nil?
  return current_size
end