Class: Clandestine::Commands::Update

Inherits:
Object
  • Object
show all
Defined in:
lib/clandestine/commands/update.rb

Instance Method Summary collapse

Constructor Details

#initialize(safe_password, key = nil) ⇒ Update

Returns a new instance of Update.



11
12
13
14
# File 'lib/clandestine/commands/update.rb', line 11

def initialize(safe_password, key = nil)
  @safe_password = safe_password
  @key = key.to_sym if key
end

Instance Method Details

#updateObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/clandestine/commands/update.rb', line 16

def update
  Safe.new(safe_password).open do |safe|
    if key
      if safe[key]
        safe.add(key, PasswordGenerator.random_password)
      else
        false
      end
    else
      new_password = IO.get_password(true).chomp
      safe.update_safe_password(new_password)
    end
  end
end