Class: StaticSync::Processor
- Inherits:
-
Object
- Object
- StaticSync::Processor
- Defined in:
- lib/static_sync/processor.rb
Defined Under Namespace
Classes: ConflictError
Instance Method Summary collapse
- #handle_conflict(file) ⇒ Object
-
#initialize(config, storage = nil) ⇒ Processor
constructor
A new instance of Processor.
- #local_filtered_files ⇒ Object
- #sync ⇒ Object
Constructor Details
#initialize(config, storage = nil) ⇒ Processor
Returns a new instance of Processor.
12 13 14 15 |
# File 'lib/static_sync/processor.rb', line 12 def initialize(config, storage = nil) @config = config @storage = storage || StaticSync::Storage.new(config) end |
Instance Method Details
#handle_conflict(file) ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/static_sync/processor.rb', line 41 def handle_conflict(file) log.info("Overwriting #{file}") if @config.log if @config.fail_on_conflict? raise ConflictError, "modifications to existing files are not allowed." elsif @config.fail_on_conflict_if_cached? if file.cached? raise ConflictError, "modifications to existing cached files are not allowed." end end end |
#local_filtered_files ⇒ Object
52 53 54 55 56 |
# File 'lib/static_sync/processor.rb', line 52 def local_filtered_files local_files.reject do |file| file =~ Regexp.new(@config.ignored) if @config.ignored end end |
#sync ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/static_sync/processor.rb', line 17 def sync log.info("Synching #{@config.local_directory} to #{@config.remote_directory}.") if @config.log Dir.chdir(@config.local_directory) 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) handle_conflict(current_file) 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 |