Class: KeyChain
- Inherits:
-
Object
- Object
- KeyChain
- Defined in:
- lib/keychain.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
- #account ⇒ Object
-
#initialize(key) ⇒ KeyChain
constructor
A new instance of KeyChain.
- #query(prompt, account) ⇒ Object
- #set(account, password) ⇒ Object
Constructor Details
#initialize(key) ⇒ KeyChain
Returns a new instance of KeyChain.
13 14 15 |
# File 'lib/keychain.rb', line 13 def initialize(key) @key = key end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
11 12 13 |
# File 'lib/keychain.rb', line 11 def key @key end |
Instance Method Details
#account ⇒ Object
18 19 20 21 22 23 |
# File 'lib/keychain.rb', line 18 def account radiko = Pit.get(key) if radiko.has_key? :account and radiko.has_key? :password [ radiko[:account], Base64.decode64(radiko[:password]) ] end end |
#query(prompt, account) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/keychain.rb', line 32 def query(prompt, account) old_account, old_password = account() puts prompt print ' password : ' STDOUT.flush new_password = STDIN.noecho(&:gets).chomp puts case when new_password.empty? raise "空のパスワードは無効です (何も変更されません)" when new_password == old_password raise "旧パスワードと同じパスワードです" end new_password end |
#set(account, password) ⇒ Object
26 27 28 29 |
# File 'lib/keychain.rb', line 26 def set(account, password) Pit.set(key, data: { account: account, password: Base64.encode64(password)}) [account, password] end |