Sha256: 2ef2a9482c751b228b72fc5affbb919da250afc21875947f93d430e9b5a3142c

Contents?: true

Size: 875 Bytes

Versions: 2

Compression:

Stored size: 875 Bytes

Contents

# frozen_string_literal: true

module Deadpull
  module Commands
    class Pull < S3Command
      extend Dry::Initializer

      param(:path, proc { |path| path.is_a?(Pathname) ? path : Pathname.new(File.expand_path(path)) })
      param :configuration, default: proc { Values::Configuration.concretize }
      param :environment, default: proc { Values::Environment.concretize }

      def call
        ensure_target_is_not_a_file
        objects.each do |object|
          location = Values::LocalLocation.concretize(path, s3_locations.prefix, object.key)
          object.download_file(location)
        end
        true
      end

      private

      def objects
        bucket.objects(prefix: s3_locations.prefix)
      end

      def ensure_target_is_not_a_file
        raise(ArgumentError, "#{path} is a regular file") if File.file?(path)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
deadpull-0.1.1 lib/deadpull/commands/pull.rb
deadpull-0.1.0 lib/deadpull/commands/pull.rb