nakajima-key-valerie 0.0.3 → 0.0.4

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/val.rb +16 -4
  2. metadata +1 -1
data/lib/val.rb CHANGED
@@ -24,6 +24,11 @@
24
24
  #
25
25
  # TODO Real options
26
26
  require 'yaml'
27
+ begin
28
+ require 'crypt/blowfish'
29
+ rescue LoadError
30
+ puts "You must install the `crypt` gem."
31
+ end
27
32
 
28
33
  class KeyValerie
29
34
  def run(args)
@@ -57,29 +62,36 @@ class KeyValerie
57
62
  puts "- #{key}: #{val}"
58
63
  end
59
64
  end
60
-
65
+
61
66
  def each
62
67
  store.each { |key,val| yield(key,val) }
63
68
  end
64
-
69
+
65
70
  def keys
66
71
  store.keys
67
72
  end
68
73
 
69
74
  private
70
75
 
76
+ def crypter
77
+ @crypter ||= Crypt::Blowfish.new('val-crypt-key')
78
+ end
79
+
71
80
  def init
72
81
  File.open(tokens, 'w+') { |f| f << '' }
73
82
  end
74
83
 
75
84
  def save(new_store)
76
85
  File.open(tokens, 'w+') do |file|
77
- YAML.dump(store, file)
86
+ file << crypter.encrypt_string(store.to_yaml)
78
87
  end
79
88
  end
80
89
 
81
90
  def store
82
- @store ||= YAML.load_file(tokens) || {}
91
+ @store ||= begin
92
+ text = File.read(tokens)
93
+ text.empty? ? {} : YAML.load(crypter.decrypt_string(text))
94
+ end
83
95
  end
84
96
 
85
97
  def tokens
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nakajima-key-valerie
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pat Nakajima