travis-ci
320 of 320 new or added lines in 20 files covered. (100.0%)
552 of 738 relevant lines covered (74.8%)
49735.38 hits per line
|
module AnyStyle |
1✔ |
|
require 'gdbm'
|
1✔ |
3 |
|
|
|
class Dictionary |
1✔ |
|
class GDBM < Dictionary |
1✔ |
|
@defaults = {
|
1✔ |
7 |
path: File.expand_path('../data/dict.db', __FILE__), |
|
8 |
mode: 0666, |
|
9 |
flags: ::GDBM::WRCREAT # | ::GDBM::NOLOCK |
|
10 |
} |
|
11 |
|
|
|
attr_reader :env
|
1✔ |
13 |
|
|
|
def initialize(options = {}) |
1✔ |
|
super(self.class.defaults.merge(options)) |
2✔ |
16 |
end
|
|
17 |
|
|
|
def open |
1✔ |
|
close |
1✔ |
|
@db = ::GDBM.new(*options.values_at(:path, :mode, :flags)) |
1✔ |
|
self
|
1✔ |
22 |
ensure
|
|
|
populate! if empty?
|
1✔ |
24 |
end
|
|
25 |
|
|
|
def close |
1✔ |
|
db.close if open?
|
3✔ |
28 |
end
|
|
29 |
|
|
|
def open? |
1✔ |
|
!(db.nil? || db.closed?) |
6✔ |
32 |
end
|
|
33 |
|
|
|
def empty? |
1✔ |
|
open? and db.empty?
|
1✔ |
36 |
end
|
|
37 |
|
|
|
def truncate |
1✔ |
|
close |
× |
|
File.unlink(options[:path]) |
× |
41 |
end
|
|
42 |
|
|
|
def get(key) |
1✔ |
|
db[key.to_s].to_i |
154,652✔ |
45 |
end
|
|
46 |
|
|
|
def put(key, value) |
1✔ |
|
db[key.to_s] = value.to_i.to_s |
147,843✔ |
49 |
end
|
|
50 |
end
|
|
51 |
end
|
|
52 |
end
|