Class: SyncFog::SyncFogUpload
- Inherits:
-
Object
- Object
- SyncFog::SyncFogUpload
- Defined in:
- lib/sync_fog/sync_fog_upload.rb
Instance Method Summary collapse
-
#clean_remote(keep_files) ⇒ Object
Removing files.
-
#initialize(container, config) ⇒ SyncFogUpload
constructor
A new instance of SyncFogUpload.
-
#public_url ⇒ Object
infos.
- #remove_file(file, keep_files_string) ⇒ Object
-
#upload(files, dir) ⇒ Object
uploading files.
- #upload_file(source_file, dir) ⇒ Object
Constructor Details
#initialize(container, config) ⇒ SyncFogUpload
Returns a new instance of SyncFogUpload.
13 14 15 16 17 18 19 20 21 |
# File 'lib/sync_fog/sync_fog_upload.rb', line 13 def initialize(container,config) @fog_service = Fog::Storage.new(config) @container = @fog_service.directories.get(container) @skip = SyncFog.configuration.skip_existing @num_threads = SyncFog.configuration.num_threads @meta = SyncFog.configuration.fog_attributes @check_zip = SyncFog.configuration.use_gzip end |
Instance Method Details
#clean_remote(keep_files) ⇒ Object
Removing files
57 58 59 60 61 62 63 |
# File 'lib/sync_fog/sync_fog_upload.rb', line 57 def clean_remote(keep_files) keep_files_string = keep_files.map{|f| f.to_s} Parallel.map(@container.files,in_threads: @num_threads) do |file| remove_file(file,keep_files_string) end end |
#public_url ⇒ Object
infos
74 75 76 |
# File 'lib/sync_fog/sync_fog_upload.rb', line 74 def public_url @container.public_url end |
#remove_file(file, keep_files_string) ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/sync_fog/sync_fog_upload.rb', line 65 def remove_file(file,keep_files_string) unless keep_files_string.include?(file.key) || keep_files_string.include?("#{file.key}.gz") p "SyncFog: -> removing #{file.key}" file.destroy end end |
#upload(files, dir) ⇒ Object
uploading files
24 25 26 27 28 29 |
# File 'lib/sync_fog/sync_fog_upload.rb', line 24 def upload(files,dir) Parallel.map(files,in_threads: @num_threads) do |source_file| upload_file(source_file,dir) end end |
#upload_file(source_file, dir) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/sync_fog/sync_fog_upload.rb', line 31 def upload_file(source_file,dir) path = dir + source_file name = source_file.to_s = @meta return if File.directory?(path) = {} zipped = false if @check_zip && File.extname(path) == ".gz" name = name.gsub('.gz','') = {content_encoding: 'gzip'}.merge( ) zipped = true end return if @skip && @container.files.head(name) content_type = MultiMime.type_for_path( name ) File.open(path) do |data| @container.files.create( key: name, body: data, metadata: , content_type: content_type, content_encoding: zipped ? 'gzip' : nil ) end end |