Class: CoralBackup::FileSelector
- Inherits:
-
Object
- Object
- CoralBackup::FileSelector
- Defined in:
- lib/coral_backup/file_selector.rb
Instance Attribute Summary collapse
-
#files ⇒ Object
readonly
Returns the value of attribute files.
Class Method Summary collapse
Instance Method Summary collapse
- #add_file(filename) ⇒ Object
-
#initialize ⇒ FileSelector
constructor
A new instance of FileSelector.
Constructor Details
#initialize ⇒ FileSelector
Returns a new instance of FileSelector.
8 9 10 |
# File 'lib/coral_backup/file_selector.rb', line 8 def initialize @files = [] end |
Instance Attribute Details
#files ⇒ Object (readonly)
Returns the value of attribute files.
6 7 8 |
# File 'lib/coral_backup/file_selector.rb', line 6 def files @files end |
Class Method Details
.select ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/coral_backup/file_selector.rb', line 20 def self.select file_selector = new Readline.completion_proc = Readline::FILENAME_COMPLETION_PROC while buf = Readline.readline("> ") = Shellwords.split(buf) warn "WARNING: #{expanded.length} files are being added:" unless .length == 1 .each do |ex| begin file_selector.add_file(ex) rescue Errno::ENOENT => e warn e else warn ex end end end file_selector.files.uniq end |
.single_select ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/coral_backup/file_selector.rb', line 42 def self.single_select file_selector = new Readline.completion_proc = Readline::FILENAME_COMPLETION_PROC file_added = false while !file_added && buf = Readline.readline("> ") = Shellwords.split(buf) warn "WARNING: #{expanded.length} files are being added:" unless .length == 1 .each do |ex| begin file_selector.add_file(ex) rescue Errno::ENOENT => e warn e else warn ex file_added = true end end end unless file_selector.files.length == 1 warn "ERROR: Wrong number of directories (#{file_selector.files.length} for 1):" file_selector.files.each do |e| warn e end exit 1 end file_selector.files[0] end |
Instance Method Details
#add_file(filename) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/coral_backup/file_selector.rb', line 12 def add_file(filename) if FileTest.exist?(filename) @files << filename else raise Errno::ENOENT, filename end end |