Class: FileReplicator::Joiner
- Inherits:
-
Object
- Object
- FileReplicator::Joiner
- Includes:
- ReplicatorHelper
- Defined in:
- lib/file_replicator/joiner.rb
Constant Summary
Constants included from ReplicatorHelper
Instance Attribute Summary
Attributes included from ReplicatorHelper
Instance Method Summary collapse
-
#initialize ⇒ Joiner
constructor
A new instance of Joiner.
- #join ⇒ Object
Constructor Details
#initialize ⇒ Joiner
Returns a new instance of Joiner.
11 12 13 14 |
# File 'lib/file_replicator/joiner.rb', line 11 def initialize = JoinerCmdParse.new. @colour = Pastel.new enabled: ![:no_colour] end |
Instance Method Details
#join ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/file_replicator/joiner.rb', line 16 def join files = Dir.glob( File.join( File.dirname([:first]), '*' ) ).sort prepare [:output_path] output_file = File.open [:output_path], 'ab' first_index = files.index File.([:first]) last_index = files.index File.([:last]) if progress? file_pb = ProgressBar.create( total: (first_index..last_index).size, title: colour.bright_blue("#{File.basename output_file}") ) end files[first_index..last_index].each do |file| File.open file, 'rb' do |f| while (data = f.read(READ_BUFFER)) output_file.write data end end file_pb.increment if progress? end file_pb.finish if progress? rescue StandardError => e puts @colour.bright_red e. unless quiet? file_pb.stop if progress? exit 1 ensure output_file.close unless output_file.nil? end |