Class: StaticSync::Processor

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

Defined Under Namespace

Classes: ImmutableError

Instance Method Summary collapse

Constructor Details

#initialize(config, storage = nil) ⇒ Processor

Returns a new instance of Processor.



13
14
15
16
# File 'lib/static_sync/processor.rb', line 13

def initialize(config, storage = nil)
  @config  = config
  @storage = storage || StaticSync::Storage.new(config)
end

Instance Method Details

#local_filtered_filesObject



45
46
47
48
49
# File 'lib/static_sync/processor.rb', line 45

def local_filtered_files
  local_files.reject do |file|
    file =~ Regexp.new(@config.ignored) if @config.ignored
  end
end

#syncObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/static_sync/processor.rb', line 18

def sync
  log.info("Synching #{@config.source} to #{@config.target}.") if @config.log
  Dir.chdir(@config.source) do
    local_filtered_files.each do |file|
      current_file = Uploadable.new(file, @config)

      unless @storage.has_version?(current_file.version)
        if @storage.has_file?(current_file.version)
          log.info("Overwriting #{file}") if @config.log
          if @config.immutable_mode
            raise ImmutableError, "immutable_mode does not allow modifications to existing files."
          end
        else
          log.info("Uploading #{file}") if @config.log
        end
        begin
          @storage.create(current_file.headers)
        rescue => error
          log.error("Failed to upload #{file}")
          raise error
        end
      end
    end
  end
  log.info("Synching done.") if @config.log
end