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
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 22 def self.select file_selector = new Readline.completion_proc = Readline::FILENAME_COMPLETION_PROC while buf = Readline.readline("> ") = Shellwords.split(buf) warn "WARNING: #{.length} files are being added:" unless .length == 1 .each do |ex| begin file_selector.add_file(ex) rescue Errno::ENOENT => e warn e 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 |
# 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: #{.length} files are being added:" unless .length == 1 .each do |ex| begin file_selector.add_file(ex) rescue Errno::ENOENT => e warn e else file_added = true end end end raise "Wrong number of files (#{file_selector.files.length} for 1)" unless file_selector.files.length == 1 file_selector.files[0] end |
Instance Method Details
#add_file(filename) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/coral_backup/file_selector.rb', line 12 def add_file(filename) if FileTest.exist?(filename) = File.(filename) @files << File.() warn else raise Errno::ENOENT, filename end end |