Sha256: 9c6ae3cef86212f888573ba4b4bc297b4e017ec70e040dbe529b70efe5d4fe65
Contents?: true
Size: 1.66 KB
Versions: 4
Compression:
Stored size: 1.66 KB
Contents
# encoding: utf-8 module Imap::Backup module Configuration; end class Configuration::FolderChooser attr_reader :account def initialize(account) @account = account end def run if connection.nil? Imap::Backup.logger.warn 'Connection failed' highline.ask 'Press a key ' return end if folders.nil? Imap::Backup.logger.warn 'Unable to get folder list' highline.ask 'Press a key ' return end catch :done do loop do system('clear') show_menu end end end private def show_menu highline.choose do |menu| menu.header = 'Add/remove folders' menu.index = :number add_folders menu menu.choice('return to the account menu') { throw :done } menu.hidden('quit') { throw :done } end end def add_folders(menu) folders.each do |folder| name = folder.name mark = is_selected?(name) ? '+' : '-' menu.choice("#{mark} #{name}") do toggle_selection name end end end def is_selected?(folder_name) account[:folders].find { |f| f[:name] == folder_name } end def toggle_selection(folder_name) if is_selected?(folder_name) account[:folders].reject! { |f| f[:name] == folder_name } else account[:folders] << { :name => folder_name } end end def connection @connection ||= Account::Connection.new(account) rescue => e nil end def folders @folders ||= connection.folders end def highline Configuration::Setup.highline end end end
Version data entries
4 entries across 4 versions & 1 rubygems