Class: Parol::Database

Inherits:
Object
  • Object
show all
Defined in:
lib/parol/database.rb

Instance Method Summary collapse

Constructor Details

#initialize(database, password) ⇒ Database

Returns a new instance of Database.



11
12
13
14
15
16
17
18
19
20
# File 'lib/parol/database.rb', line 11

def initialize database, password
  @database = database
  @password = password

  @binary_password = String.new @password, encoding: 'BINARY'
  @box = RbNaCl::SimpleBox.from_secret_key @binary_password

  rescue RbNaCl::LengthError
    raise BadPasswordLength
end

Instance Method Details

#accounts(&block) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/parol/database.rb', line 35

def accounts &block
  data = decrypt

  if block_given?
    data.each do |h|
      yield h
    end
  else
    data
  end
end

#add(program, login, password, notes) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/parol/database.rb', line 22

def add program, , password, notes
  data = decrypt

  data << {
      program: program,
      login: ,
      password: password,
      notes: notes
  }

  encrypt data
end

#save(data) ⇒ Object



47
48
49
# File 'lib/parol/database.rb', line 47

def save data
  encrypt data
end