lib/keepassx/database.rb in ruby-keepassx-0.2.1 vs lib/keepassx/database.rb in ruby-keepassx-0.2.2beta1
- old
+ new
@@ -9,11 +9,11 @@
attr_accessor :password, :key_file, :path
def self.open opts
path = opts.to_s
- fail "File #{path} does not exist." unless File.exist? path
+ fail IOError, "File #{path} does not exist." unless File.exist? path
db = self.new path
return db unless block_given?
yield db
end
@@ -117,11 +117,11 @@
if opts.empty?
# Return all items if no selection condition was provided
items = item_list
else
- opts = {:title => opts.to_s} if opts.is_a? String or opts.is_a? Symbol
+ opts = { :title => opts.to_s } if opts.is_a? String or opts.is_a? Symbol
match_number = opts.length
items = []
opts.each do |k, v|
items += Array(item_list.select { |e| e.send(k).eql?(v) })
@@ -232,10 +232,11 @@
if opts.is_a? Hash
opts = deep_copy opts
opts[:id] = next_group_id unless opts.has_key? :id
+ # Replace parent, which is specified by symbol with actual group
if opts[:parent].is_a? Symbol
group = self.group opts[:parent]
fail "Group #{opts[:parent].inspect} does not exist" if group.nil?
opts[:parent] = group
end
@@ -462,7 +463,14 @@
result = []
groups(:level => 0).each { |group| result << build_branch(group) }
result
end
+
+ # Dump YAML representation of database.
+ #
+ # @return [String]
+ def to_yaml
+ YAML.dump to_a
+ end
end
end