Module: Keepassx::Database::Dumper
- Included in:
- Keepassx::Database
- Defined in:
- lib/keepassx/database/dumper.rb
Instance Method Summary collapse
-
#save(opts = {}) ⇒ Fixnum
Save database to file storage.
-
#to_a(opts = {}) ⇒ Array
Dump Array representation of database.
-
#to_yaml(opts = {}) ⇒ String
Dump YAML representation of database.
Instance Method Details
#save(opts = {}) ⇒ Fixnum
Save database to file storage
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/keepassx/database/dumper.rb', line 29 def save(opts = {}) path = opts.delete(:path) { nil } password = opts.delete(:password) { nil } new_path = path || @path new_password = password || @password raise ArgumentError, 'File path is not set' if new_path.nil? raise ArgumentError, 'Password is not set' if new_password.nil? File.open(new_path, 'wb') do |file| file.write dump(new_password) end end |
#to_a(opts = {}) ⇒ Array
Dump Array representation of database.
10 11 12 13 14 |
# File 'lib/keepassx/database/dumper.rb', line 10 def to_a(opts = {}) result = [] find_groups(level: 0).each { |group| result << build_branch(group, opts) } result end |
#to_yaml(opts = {}) ⇒ String
Dump YAML representation of database.
20 21 22 |
# File 'lib/keepassx/database/dumper.rb', line 20 def to_yaml(opts = {}) YAML.dump to_a(opts) end |