Sha256: 1a677fe50ce03d95a1ec78b6f8133b9471cfe168bed25fe498114ae243ebe587

Contents?: true

Size: 1.76 KB

Versions: 39

Compression:

Stored size: 1.76 KB

Contents

require 'fulmar/infrastructure/service/transfer/base'

module Fulmar
  module Infrastructure
    module Service
      module Transfer
        # Implements the rsync transfer
        class Tar < Base
          DEFAULT_CONFIG = {
            tar: {
              format: 'gz', # 'bz2'
              file_base: nil,
              # exclude: "*.bak",
              # filename: "site.tar.gz"
            }
          }

          def initialize(config)
            @config = DEFAULT_CONFIG.deep_merge(config)

            @config[:tar][:file_base] = File.basename(@config[:local_path]) if @config[:tar][:file_base].nil?

            super(@config)
          end

          def transfer
            prepare unless @prepared
            @local_shell.run tar_command
            filename
          end

          # Build the rsync command from the given options
          def tar_command
            "tar #{tar_command_options} '#{filename}' '#{config[:local_path]}'"
          end

          protected

          def filename
            return @config[:tar][:filename] unless @config[:tar][:filename].blank?
            @config[:tar][:file_base] + '_' + Time.now.strftime('%Y-%m-%d') + extension
          end

          def extension
            @config[:tar][:format].blank? ? '.tar' : '.tar.' + @config[:tar][:format]
          end

          # Assembles all rsync command line parameters from the configuration options
          def tar_command_options
            options = ['-c']
            options << '-j' if @config[:tar][:format] == 'bz2'
            options << '-z' if @config[:tar][:format] == 'gz'
            options << "--exclude #{@config[:tar][:exclude]}" if @config[:tar][:exclude]
            options << '-f'
            options.join(' ')
          end
        end
      end
    end
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
fulmar-1.8.0 lib/fulmar/infrastructure/service/transfer/tar.rb
fulmar-1.7.5 lib/fulmar/infrastructure/service/transfer/tar.rb
fulmar-1.7.4 lib/fulmar/infrastructure/service/transfer/tar.rb
fulmar-1.7.3 lib/fulmar/infrastructure/service/transfer/tar.rb
fulmar-1.7.2 lib/fulmar/infrastructure/service/transfer/tar.rb
fulmar-1.7.1 lib/fulmar/infrastructure/service/transfer/tar.rb
fulmar-1.7.0 lib/fulmar/infrastructure/service/transfer/tar.rb
fulmar-1.6.4 lib/fulmar/infrastructure/service/transfer/tar.rb
fulmar-1.6.3 lib/fulmar/infrastructure/service/transfer/tar.rb
fulmar-1.6.2 lib/fulmar/infrastructure/service/transfer/tar.rb
fulmar-1.6.1 lib/fulmar/infrastructure/service/transfer/tar.rb
fulmar-1.6.0 lib/fulmar/infrastructure/service/transfer/tar.rb
fulmar-1.5.2 lib/fulmar/infrastructure/service/transfer/tar.rb
fulmar-1.5.1 lib/fulmar/infrastructure/service/transfer/tar.rb
fulmar-1.5.0 lib/fulmar/infrastructure/service/transfer/tar.rb
fulmar-1.4.2 lib/fulmar/infrastructure/service/transfer/tar.rb
fulmar-1.4.1 lib/fulmar/infrastructure/service/transfer/tar.rb
fulmar-1.4.0 lib/fulmar/infrastructure/service/transfer/tar.rb
fulmar-1.3.0 lib/fulmar/infrastructure/service/transfer/tar.rb