Module: Persist::LevelDBAdapter

Defined in:
lib/rbbt/persist/tsv/leveldb.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#closedObject

Returns the value of attribute closed.



6
7
8
# File 'lib/rbbt/persist/tsv/leveldb.rb', line 6

def closed
  @closed
end

#persistence_pathObject

Returns the value of attribute persistence_path.



6
7
8
# File 'lib/rbbt/persist/tsv/leveldb.rb', line 6

def persistence_path
  @persistence_path
end

#writableObject

Returns the value of attribute writable.



6
7
8
# File 'lib/rbbt/persist/tsv/leveldb.rb', line 6

def writable
  @writable
end

Class Method Details

.open(path, write) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/rbbt/persist/tsv/leveldb.rb', line 8

def self.open(path, write)

  database = CONNECTIONS[path] ||= begin
                                     LevelDB::DB.new path
                                   end

  database.extend Persist::LevelDBAdapter unless Persist::LevelDBAdapter === database
  database.persistence_path ||= path

  database
end

Instance Method Details

#closeObject



37
38
39
# File 'lib/rbbt/persist/tsv/leveldb.rb', line 37

def close
  @closed = true
end

#closed?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/rbbt/persist/tsv/leveldb.rb', line 33

def closed?
  @closed
end

#delete(key) ⇒ Object



53
54
55
# File 'lib/rbbt/persist/tsv/leveldb.rb', line 53

def delete(key)
  out(key)
end

#get_prefix(key) ⇒ Object



24
25
26
27
# File 'lib/rbbt/persist/tsv/leveldb.rb', line 24

def get_prefix(key)
  keys = prefix(key)
  select(:key => keys)
end

#include?(key) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/rbbt/persist/tsv/leveldb.rb', line 29

def include?(key)
  includes?(key)
end

#merge!(hash) ⇒ Object



93
94
95
96
97
# File 'lib/rbbt/persist/tsv/leveldb.rb', line 93

def merge!(hash)
  hash.each do |key,values|
    self[key] = values
  end
end

#prefix(key) ⇒ Object



20
21
22
# File 'lib/rbbt/persist/tsv/leveldb.rb', line 20

def prefix(key)
  range(key, 1, key + 255.chr, 1)
end

#range(*args) ⇒ Object



100
101
102
# File 'lib/rbbt/persist/tsv/leveldb.rb', line 100

def range(*args)
  super(*args) - TSV::ENTRY_KEYS.to_a
end

#read(force = false) ⇒ Object



41
42
43
# File 'lib/rbbt/persist/tsv/leveldb.rb', line 41

def read(force = false)
  self
end

#read_and_closeObject



83
84
85
86
87
88
89
90
91
# File 'lib/rbbt/persist/tsv/leveldb.rb', line 83

def read_and_close
  read if @closed or write?
  res = begin
          yield
        ensure
          close
        end
  res
end

#write(force = true) ⇒ Object



45
46
47
# File 'lib/rbbt/persist/tsv/leveldb.rb', line 45

def write(force = true)
  self
end

#write?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/rbbt/persist/tsv/leveldb.rb', line 49

def write?
  @writable
end

#write_and_closeObject



70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/rbbt/persist/tsv/leveldb.rb', line 70

def write_and_close
  lock_filename = Persist.persistence_path(persistence_path, {:dir => TSV.lock_dir})
  Misc.lock(lock_filename) do
    write if @closed or not write?
    res = begin
            yield
          ensure
            close
          end
    res
  end
end

#write_and_readObject



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/rbbt/persist/tsv/leveldb.rb', line 57

def write_and_read
  lock_filename = Persist.persistence_path(persistence_path, {:dir => TSV.lock_dir})
  Misc.lock(lock_filename) do
    write if @closed or not write?
    res = begin
            yield
          ensure
            read
          end
    res
  end
end