lib/imap/backup/configuration/account.rb in imap-backup-2.1.0 vs lib/imap/backup/configuration/account.rb in imap-backup-2.1.1

- old
+ new

@@ -1,9 +1,9 @@ module Imap::Backup module Configuration; end - class Configuration::Account < Struct.new(:store, :account, :highline) + Configuration::Account = Struct.new(:store, :account, :highline) do def initialize(store, account, highline) super end def run @@ -49,11 +49,13 @@ Kernel.puts "username: #{username}" other_accounts = store.accounts.reject { |a| a == account } others = other_accounts.map { |a| a[:username] } Kernel.puts "others: #{others.inspect}" if others.include?(username) - Kernel.puts "There is already an account set up with that email address" + Kernel.puts( + "There is already an account set up with that email address" + ) else account[:username] = username if account[:server].nil? || (account[:server] == "") account[:server] = default_server(username) end @@ -80,26 +82,28 @@ account[:modified] = true end end end + def path_modification_validator(path) + same = store.accounts.find do |a| + a[:username] != account[:username] && a[:local_path] == path + end + if same + Kernel.puts "The path '#{path}' is used to backup " \ + "the account '#{same[:username]}'" + false + else + true + end + end + def modify_backup_path(menu) menu.choice("modify backup path") do - validator = ->(p) do - same = store.accounts.find do |a| - a[:username] != account[:username] && a[:local_path] == p - end - if same - Kernel.puts "The path '#{p}' is used to backup " \ - "the account '#{same[:username]}'" - false - else - true - end - end existing = account[:local_path].clone - account[:local_path] = - Configuration::Asker.backup_path(account[:local_path], validator) + account[:local_path] = Configuration::Asker.backup_path( + account[:local_path], ->(path) { path_modification_validator(path) } + ) account[:modified] = true if existing != account[:local_path] end end def choose_folders(menu)