Class: Clandestine::Commands::Add

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

Instance Method Summary collapse

Constructor Details

#initialize(safe_password, key) ⇒ Add

Returns a new instance of Add.



12
13
14
15
16
# File 'lib/clandestine/commands/add.rb', line 12

def initialize(safe_password, key)
  raise ClandestineError.new 'Missing required key argument' unless key
  @safe_password = safe_password
  @key = key.to_sym
end

Instance Method Details

#addObject



18
19
20
21
22
23
24
25
26
# File 'lib/clandestine/commands/add.rb', line 18

def add
  Safe.new(safe_password).open do |safe|
    if !safe.exists?(key)
      safe.add(key, PasswordGenerator.random_password)
    else
      false
    end
  end
end