key-db 2.0.3 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/keydb.rb +28 -9
 - metadata +3 -4
 
    
        data/lib/keydb.rb
    CHANGED
    
    | 
         @@ -11,7 +11,7 @@ class KeyDB 
     | 
|
| 
       11 
11 
     | 
    
         
             
              end
         
     | 
| 
       12 
12 
     | 
    
         | 
| 
       13 
13 
     | 
    
         
             
              def new_key keyname, value
         
     | 
| 
       14 
     | 
    
         
            -
                if keyname =~  
     | 
| 
      
 14 
     | 
    
         
            +
                if keyname =~ /\/|\(---\)/
         
     | 
| 
       15 
15 
     | 
    
         
             
                  raise "Invalid Keyname!"
         
     | 
| 
       16 
16 
     | 
    
         
             
                  return
         
     | 
| 
       17 
17 
     | 
    
         
             
                end
         
     | 
| 
         @@ -35,6 +35,11 @@ class KeyDB 
     | 
|
| 
       35 
35 
     | 
    
         
             
                if keyname.class != String
         
     | 
| 
       36 
36 
     | 
    
         
             
                  warn "WARNING: Keyname should be a string"
         
     | 
| 
       37 
37 
     | 
    
         
             
                end
         
     | 
| 
      
 38 
     | 
    
         
            +
                File.open(@filename, "r").each_line do |line|
         
     | 
| 
      
 39 
     | 
    
         
            +
                  if Marshal.load(line).split("(---)")[1] == keyname
         
     | 
| 
      
 40 
     | 
    
         
            +
                    return "Key has been deleted"
         
     | 
| 
      
 41 
     | 
    
         
            +
                  end
         
     | 
| 
      
 42 
     | 
    
         
            +
                end
         
     | 
| 
       38 
43 
     | 
    
         
             
                File.open(@filename, "r").each_line do |line|
         
     | 
| 
       39 
44 
     | 
    
         
             
                  line = Marshal.load(line)
         
     | 
| 
       40 
45 
     | 
    
         
             
                  if line.split("/")[0] == keyname
         
     | 
| 
         @@ -43,27 +48,41 @@ class KeyDB 
     | 
|
| 
       43 
48 
     | 
    
         
             
                end
         
     | 
| 
       44 
49 
     | 
    
         
             
              end
         
     | 
| 
       45 
50 
     | 
    
         | 
| 
      
 51 
     | 
    
         
            +
              def delete_key keyname
         
     | 
| 
      
 52 
     | 
    
         
            +
                @db_file = File.open(@filename, "a")
         
     | 
| 
      
 53 
     | 
    
         
            +
                @db_file.write(Marshal.dump("DK(---)#{keyname}"))
         
     | 
| 
      
 54 
     | 
    
         
            +
                @db_file.write("\n")
         
     | 
| 
      
 55 
     | 
    
         
            +
                @db_file.close
         
     | 
| 
      
 56 
     | 
    
         
            +
              end
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
       46 
58 
     | 
    
         
             
              def access_all type
         
     | 
| 
       47 
59 
     | 
    
         
             
                File.open(@filename).each_line do |line|
         
     | 
| 
       48 
60 
     | 
    
         
             
                  line = Marshal.load(line)
         
     | 
| 
       49 
61 
     | 
    
         
             
                  @keys_and_vals = line.split('/')
         
     | 
| 
       50 
62 
     | 
    
         
             
                  if type == "keys"
         
     | 
| 
       51 
     | 
    
         
            -
                     
     | 
| 
      
 63 
     | 
    
         
            +
                    if line.split("(---)").length == 2
         
     | 
| 
      
 64 
     | 
    
         
            +
                      puts
         
     | 
| 
      
 65 
     | 
    
         
            +
                    else
         
     | 
| 
      
 66 
     | 
    
         
            +
                      puts @keys_and_vals[0]
         
     | 
| 
      
 67 
     | 
    
         
            +
                    end
         
     | 
| 
       52 
68 
     | 
    
         
             
                  elsif type == "vals"
         
     | 
| 
       53 
     | 
    
         
            -
                     
     | 
| 
      
 69 
     | 
    
         
            +
                    if line.split("(---)").length == 2
         
     | 
| 
      
 70 
     | 
    
         
            +
                      puts
         
     | 
| 
      
 71 
     | 
    
         
            +
                    else
         
     | 
| 
      
 72 
     | 
    
         
            +
                      puts @keys_and_vals[1]
         
     | 
| 
      
 73 
     | 
    
         
            +
                    end
         
     | 
| 
       54 
74 
     | 
    
         
             
                  elsif type == "all"
         
     | 
| 
       55 
     | 
    
         
            -
                     
     | 
| 
      
 75 
     | 
    
         
            +
                    if line.split("(---)").length == 2
         
     | 
| 
      
 76 
     | 
    
         
            +
                      puts
         
     | 
| 
      
 77 
     | 
    
         
            +
                    else
         
     | 
| 
      
 78 
     | 
    
         
            +
                      puts line
         
     | 
| 
      
 79 
     | 
    
         
            +
                    end
         
     | 
| 
       56 
80 
     | 
    
         
             
                  else
         
     | 
| 
       57 
81 
     | 
    
         
             
                    raise "Invalid Argument"
         
     | 
| 
       58 
82 
     | 
    
         
             
                  end
         
     | 
| 
       59 
83 
     | 
    
         
             
                end
         
     | 
| 
       60 
84 
     | 
    
         
             
              end
         
     | 
| 
       61 
85 
     | 
    
         | 
| 
       62 
     | 
    
         
            -
              def count
         
     | 
| 
       63 
     | 
    
         
            -
                key_count = %x[wc -l #{@filename}].split(" ")[0]
         
     | 
| 
       64 
     | 
    
         
            -
                key_count.to_i
         
     | 
| 
       65 
     | 
    
         
            -
              end
         
     | 
| 
       66 
     | 
    
         
            -
             
     | 
| 
       67 
86 
     | 
    
         
             
              def delete_db
         
     | 
| 
       68 
87 
     | 
    
         
             
                system("rm #{@filename}")
         
     | 
| 
       69 
88 
     | 
    
         
             
              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: 2.0 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 2.1.0
         
     | 
| 
       5 
5 
     | 
    
         
             
              prerelease: 
         
     | 
| 
       6 
6 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       7 
7 
     | 
    
         
             
            authors:
         
     | 
| 
         @@ -11,9 +11,8 @@ bindir: bin 
     | 
|
| 
       11 
11 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       12 
12 
     | 
    
         
             
            date: 2012-05-13 00:00:00.000000000 Z
         
     | 
| 
       13 
13 
     | 
    
         
             
            dependencies: []
         
     | 
| 
       14 
     | 
    
         
            -
            description: ! 'A database acessible via keys.  
     | 
| 
       15 
     | 
    
         
            -
               
     | 
| 
       16 
     | 
    
         
            -
              ''keydb'''
         
     | 
| 
      
 14 
     | 
    
         
            +
            description: ! 'A database acessible via keys. Added delete_key method. Bug exists
         
     | 
| 
      
 15 
     | 
    
         
            +
              in access_all method. File to require: ''keydb'''
         
     | 
| 
       17 
16 
     | 
    
         
             
            email: slmnwise@gmail.com
         
     | 
| 
       18 
17 
     | 
    
         
             
            executables: []
         
     | 
| 
       19 
18 
     | 
    
         
             
            extensions: []
         
     |