Class: Backup::Syncer::Cloud::SyncContext

Inherits:
Object
  • Object
show all
Defined in:
lib/backup/syncer/cloud.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(directory, bucket, path) ⇒ SyncContext

Creates a new SyncContext object which handles a single directory from the Syncer::Base @directories array.



66
67
68
# File 'lib/backup/syncer/cloud.rb', line 66

def initialize(directory, bucket, path)
  @directory, @bucket, @path = directory, bucket, path
end

Instance Attribute Details

#bucketObject (readonly)

Returns the value of attribute bucket.



61
62
63
# File 'lib/backup/syncer/cloud.rb', line 61

def bucket
  @bucket
end

#directoryObject (readonly)

Returns the value of attribute directory.



61
62
63
# File 'lib/backup/syncer/cloud.rb', line 61

def directory
  @directory
end

#pathObject (readonly)

Returns the value of attribute path.



61
62
63
# File 'lib/backup/syncer/cloud.rb', line 61

def path
  @path
end

Instance Method Details

#sync!(mirror = false, concurrency_type = false, concurrency_level = 2) ⇒ Object

Performs the sync operation using the provided techniques (mirroring/concurrency).



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/backup/syncer/cloud.rb', line 72

def sync!(mirror = false, concurrency_type = false, concurrency_level = 2)
  block = Proc.new { |relative_path| sync_file relative_path, mirror }

  case concurrency_type
  when FalseClass
    all_file_names.each &block
  when :threads
    Parallel.each all_file_names, :in_threads => concurrency_level, &block
  when :processes
    Parallel.each all_file_names, :in_processes => concurrency_level, &block
  else
    raise Errors::Syncer::Cloud::ConfigurationError,
        "Unknown concurrency_type setting: #{concurrency_type.inspect}"
  end
end