class SyncFog::SyncFogUpload

Public Class Methods

new(container,config) click to toggle source
# 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

Public Instance Methods

clean_remote(keep_files) click to toggle source

Removing files

# 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() click to toggle source

infos

# File lib/sync_fog/sync_fog_upload.rb, line 74
def public_url
  @container.public_url
end
remove_file(file,keep_files_string) click to toggle source
# 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) click to toggle source

uploading files

# 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) click to toggle source
# 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 = @meta

  return if File.directory?(path)

  options = {}
  zipped = false

  if @check_zip && File.extname(path) == ".gz"
    name = name.gsub('.gz','')
    meta = {content_encoding: 'gzip'}.merge( meta )
    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: meta, content_type: content_type, content_encoding: zipped ? 'gzip' : nil )
  end
end