Class: RemoteDirectory
- Inherits:
-
Object
- Object
- RemoteDirectory
- Defined in:
- lib/processor/remote_directory.rb
Instance Method Summary collapse
-
#copy_to_s3(bucket, prefix, use_virtual_directories = false) ⇒ Object
copy each of the files in this directory up to S3.
-
#delete! ⇒ Object
delete all of the files in this directory, and the directory itself.
-
#files ⇒ Object
returns all of the files in this directory.
-
#initialize(dirname) ⇒ RemoteDirectory
constructor
pass in the string with the name of directory like “/path/to/dir”.
-
#save_file_to_s3(filename, bucket, prefix, use_virtual_directories = false) ⇒ Object
save an individual file up to S3 storage.
Constructor Details
#initialize(dirname) ⇒ RemoteDirectory
pass in the string with the name of directory like “/path/to/dir”.
46 47 48 49 |
# File 'lib/processor/remote_directory.rb', line 46 def initialize(dirname) @dirname = dirname @deleted = false end |
Instance Method Details
#copy_to_s3(bucket, prefix, use_virtual_directories = false) ⇒ Object
copy each of the files in this directory up to S3. pass in the bucket like “my-bucket”, and the prefix for storing files within the bucket like “path/to”
63 64 65 66 67 |
# File 'lib/processor/remote_directory.rb', line 63 def copy_to_s3(bucket, prefix, use_virtual_directories=false) files.each {|f| save_file_to_s3(f, bucket, prefix, use_virtual_directories) } end |
#delete! ⇒ Object
delete all of the files in this directory, and the directory itself
70 71 72 73 74 75 76 77 |
# File 'lib/processor/remote_directory.rb', line 70 def delete! # todo: implement this convenience method # return if @deleted # FileUtils.rm files # Dir.rmdir(@dirname) # @deleted = true end |
#files ⇒ Object
returns all of the files in this directory. wraps Dir.glob.
52 53 54 55 56 57 58 59 |
# File 'lib/processor/remote_directory.rb', line 52 def files result = [] return result if @dirname.nil? || @deleted Dir.chdir(@dirname) do result = Dir.glob("*") end result end |
#save_file_to_s3(filename, bucket, prefix, use_virtual_directories = false) ⇒ Object
save an individual file up to S3 storage
80 81 82 83 84 |
# File 'lib/processor/remote_directory.rb', line 80 def save_file_to_s3(filename, bucket, prefix, use_virtual_directories=false) = {:access => :public_read} [:use_virtual_directories] = true if use_virtual_directories AWS::S3::S3Object.store("/" + prefix + "/" + filename, open(File.join(@dirname, filename)), bucket, ) end |