Class: Bak::FileCopier
- Inherits:
-
Object
- Object
- Bak::FileCopier
- Defined in:
- lib/bak/copier.rb
Instance Attribute Summary collapse
-
#end_file ⇒ Object
Returns the value of attribute end_file.
-
#generator ⇒ Object
Returns the value of attribute generator.
-
#start_file ⇒ Object
Returns the value of attribute start_file.
Instance Method Summary collapse
- #check_errors ⇒ Object
-
#initialize(backupNameGenerator, output_stream) ⇒ FileCopier
constructor
A new instance of FileCopier.
- #start ⇒ Object
Constructor Details
#initialize(backupNameGenerator, output_stream) ⇒ FileCopier
Returns a new instance of FileCopier.
4 5 6 7 8 9 |
# File 'lib/bak/copier.rb', line 4 def initialize(backupNameGenerator, output_stream) @generator = backupNameGenerator @output = output_stream @start_file = @generator.filename @end_file = @generator.start end |
Instance Attribute Details
#end_file ⇒ Object
Returns the value of attribute end_file.
3 4 5 |
# File 'lib/bak/copier.rb', line 3 def end_file @end_file end |
#generator ⇒ Object
Returns the value of attribute generator.
3 4 5 |
# File 'lib/bak/copier.rb', line 3 def generator @generator end |
#start_file ⇒ Object
Returns the value of attribute start_file.
3 4 5 |
# File 'lib/bak/copier.rb', line 3 def start_file @start_file end |
Instance Method Details
#check_errors ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/bak/copier.rb', line 11 def check_errors unless File.exists?(@start_file) return "#{start_file}: No such file or directory" end if File.exists?(@end_file) && !@generator[:force] return "#{end_file}: File already exists" end if @generator[:create_path] == true FileUtils::mkdir_p @generator[:target_path] end if @generator[:target_path] && !File.directory?(@generator[:target_path]) return "#{@generator[:target_path]} directory does not exist" end end |
#start ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/bak/copier.rb', line 26 def start errors = check_errors if errors @output.puts errors else FileUtils.cp_r(start_file, end_file) end end |