key-db 1.3.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/keydb.rb +12 -9
  2. metadata +5 -3
@@ -1,5 +1,6 @@
1
1
  class KeyDB
2
-
2
+ attr_reader :filename
3
+
3
4
  def initialize filename
4
5
  @filename = filename.split(".")
5
6
  @filename = "#{@filename[0]}.db"
@@ -36,18 +37,12 @@ class KeyDB
36
37
  end
37
38
  File.open(@filename, "r").each_line do |line|
38
39
  line = Marshal.load(line)
39
- if line[keyname]
40
- val = line.split("/")
41
- puts val[1]
40
+ if line.split("/")[0] == keyname
41
+ return line.split("/")[1]
42
42
  end
43
43
  end
44
44
  end
45
45
 
46
- def recall_key keyname
47
- warn "WARNING: recall_key is deprecated, use get_key"
48
- get_key keyname
49
- end
50
-
51
46
  def access_all type
52
47
  File.open(@filename).each_line do |line|
53
48
  line = Marshal.load(line)
@@ -56,12 +51,20 @@ class KeyDB
56
51
  puts @keys_and_vals[0]
57
52
  elsif type == "vals"
58
53
  puts @keys_and_vals[1]
54
+ elsif type == "all"
55
+ puts line
59
56
  else
60
57
  raise "Invalid Argument"
61
58
  end
62
59
  end
63
60
  end
64
61
 
62
+ def count
63
+ key_count = %x[wc -l #{@filename}].split(" ")
64
+ key_count = key_count[0]
65
+ return key_count.to_i
66
+ end
67
+
65
68
  def delete_db
66
69
  system("rm #{@filename}")
67
70
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: key-db
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 2.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,8 +11,10 @@ bindir: bin
11
11
  cert_chain: []
12
12
  date: 2012-05-12 00:00:00.000000000 Z
13
13
  dependencies: []
14
- description: ! 'A database acessible via keys. Fixed key-uniqueness bug. Renamed access
15
- method to access_all. File to require: ''keydb'''
14
+ description: ! 'A database acessible via keys. Changed some ''puts'' to ''return''.
15
+ Added filename variable. Fixed key getter bug. New count method which counts the
16
+ number of keys in the database. Removed recall_key deprecation. Calls to that function
17
+ will now result in an error. File to require: ''keydb'''
16
18
  email: slmnwise@gmail.com
17
19
  executables: []
18
20
  extensions: []