Class: Yoda::Store::Adapters::GdbmAdapter

Inherits:
Base
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/yoda/store/adapters/gdbm_adapter.rb,
lib/yoda/store/adapters/gdbm_adapter/namespace_accessor.rb

Defined Under Namespace

Classes: NamespaceAccessor

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#batch_write, #clear, #delete, #empty?, #exist?, #get, #keys, #persistable?, #put, #stats, #sync

Constructor Details

#initialize(path) ⇒ GdbmAdapter

Returns a new instance of GdbmAdapter.

Parameters:

  • path (String)


30
31
32
33
34
35
# File 'lib/yoda/store/adapters/gdbm_adapter.rb', line 30

def initialize(path)
  dirname = File.dirname(path)
  FileUtils.mkdir_p(dirname) unless Dir.exist?(dirname)
  @path = path
  @database = GDBM.open(path, 0666, GDBM::NOLOCK)
end

Class Method Details

.for(path) ⇒ Object



12
13
14
15
# File 'lib/yoda/store/adapters/gdbm_adapter.rb', line 12

def for(path)
  @pool ||= {}
  @pool[path] || (@pool[path] = new(path))
end

.type ⇒ Object



17
18
19
# File 'lib/yoda/store/adapters/gdbm_adapter.rb', line 17

def type
  :gdbm
end

Instance Method Details

#inspect ⇒ String

Returns:

  • (String)


50
51
52
# File 'lib/yoda/store/adapters/gdbm_adapter.rb', line 50

def inspect
  "#<#{self.class.name}: #{self.class.type}>"
end

#namespace_for(name) ⇒ NamespaceAccessor Also known as: namespace

Parameters:

  • namespace (String, Symbol)

Returns:



43
44
45
46
# File 'lib/yoda/store/adapters/gdbm_adapter.rb', line 43

def namespace_for(name)
  @namespaces ||= {}
  @namespaces[name.to_sym] ||= NamespaceAccessor.new(database: database, namespace: name)
end

#root ⇒ Object



37
38
39
# File 'lib/yoda/store/adapters/gdbm_adapter.rb', line 37

def root
  @root ||= NamespaceAccessor.new(database: database, namespace: nil)
end