key-db 2.3.0 → 2.4.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 +13 -0
  2. metadata +5 -4
@@ -38,6 +38,8 @@ class KeyDB
38
38
  File.open(@filename, "r").each_line do |line|
39
39
  if Marshal.load(line).split("(---)")[1] == keyname
40
40
  return "Key has been deleted"
41
+ elsif Marshal.load(line).split("-***-")[1] == keyname
42
+ return Marshal.load(line).split("-***-")[2]
41
43
  end
42
44
  end
43
45
  File.open(@filename, "r").each_line do |line|
@@ -48,6 +50,13 @@ class KeyDB
48
50
  end
49
51
  end
50
52
 
53
+ def change_key keyname, value
54
+ @db_file = File.open(@filename, "a")
55
+ @db_file.write(Marshal.dump("CK-***-#{keyname}-***-#{value}"))
56
+ @db_file.write("\n")
57
+ @db_file.close
58
+ end
59
+
51
60
  def delete_key keyname
52
61
  @db_file = File.open(@filename, "a")
53
62
  @db_file.write(Marshal.dump("DK(---)#{keyname}"))
@@ -57,10 +66,14 @@ class KeyDB
57
66
 
58
67
  def access_all type
59
68
  to_ignore = []
69
+ to_change = {}
60
70
  File.open(@filename).each_line do |line|
61
71
  if Marshal.load(line).split("(---)")[1] != nil
62
72
  to_ignore.push(Marshal.load(line).split("(---)")[1])
63
73
  end
74
+ elsif Marshal.load(line).split("-***-")[1] == keyname
75
+ to_change[Marshal.load(line).split("-***-")[1]] = Marshal.load(line).split("-***-")[2]
76
+ end
64
77
  end
65
78
  File.open(@filename).each_line do |line|
66
79
  line = Marshal.load(line)
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: 2.3.0
4
+ version: 2.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,10 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-13 00:00:00.000000000 Z
12
+ date: 2012-05-15 00:00:00.000000000 Z
13
13
  dependencies: []
14
- description: ! 'A database acessible via keys. Added delete_key method and wipe_db
15
- method. Changed key validation slightly. File to require: ''keydb'''
14
+ description: ! 'A database acessible via keys. Added change_key method. change_key
15
+ method not implemented in access_all, access_all will still return the original
16
+ value. File to require: ''keydb'''
16
17
  email: slmnwise@gmail.com
17
18
  executables: []
18
19
  extensions: []