Class: StaticSync::Storage

Inherits:
Object
  • Object
show all
Defined in:
lib/static_sync/storage.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Storage

Returns a new instance of Storage.



9
10
11
12
# File 'lib/static_sync/storage.rb', line 9

def initialize(config)
  @config = config
  @meta   = Meta.new(config)
end

Instance Method Details

#syncObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/static_sync/storage.rb', line 14

def sync
  verify_remote_directory
  remote_keys = []
  remote_directory.files.each do |file|
    remote_keys << [file.key, file.etag]
  end
  log.info("Synching #{@config.source} to #{@config.target}.") if @config.log
  Dir.chdir(@config.source) do
    local_filtered_files.each do |file|
      current_file     = @meta.for(file)
      current_file_key = [current_file[:key], current_file[:etag]]

      unless remote_keys.include?(current_file_key)
        log.info("Uploading #{file}") if @config.log
        begin
          remote_directory.files.create(current_file)
        rescue => error
          log.error("Failed to upload #{file}")
          raise error
        end
      end
    end
    log.info("Synching done.") if @config.log
  end
end