Class: S3Ranger::CLI::Put

Inherits:
BaseCmd
  • Object
show all
Defined in:
lib/s3ranger/cli.rb

Instance Method Summary collapse

Methods inherited from BaseCmd

#has_options?, #has_prefix?, #usage

Constructor Details

#initializePut

Returns a new instance of Put.



281
282
283
284
285
286
# File 'lib/s3ranger/cli.rb', line 281

def initialize
  super 'put', false, false

  @short_desc = 'Upload a file to a bucket under a certain prefix'
  @has_prefix = true
end

Instance Method Details

#run(s3, bucket, key, file, args) ⇒ Object

Raises:



288
289
290
291
292
293
294
# File 'lib/s3ranger/cli.rb', line 288

def run s3, bucket, key, file, args
  raise WrongUsage.new(nil, "You need to inform a bucket") if not bucket
  raise WrongUsage.new(nil, "You need to inform a file") if not file

  name = S3Ranger.safe_join [key, File.basename(file)]
  s3.buckets[bucket].objects[name].write Pathname.new(file)
end