lib/snapsync/sync_all.rb in snapsync-0.1.5 vs lib/snapsync/sync_all.rb in snapsync-0.1.6
- old
+ new
@@ -21,46 +21,38 @@
@config_dir = config_dir
@target_dir = target_dir
@autoclean = autoclean
end
- # Whether the given target should be cleaned after synchronization.
- #
- # This is determined either by {#autoclean?} if {.new} was called with
- # true or false, or by the target's own autoclean flag if {.new} was
- # called with nil
- def should_autoclean_target?(target)
- if @autoclean.nil?
- target.autoclean?
- else
- @autoclean
- end
+ # Whether the target should be forced to autoclean(true), force to not
+ # run cleanup (false) or use their own config file to decide (nil)
+ #
+ # The default is nil
+ #
+ # @return [Boolean,nil]
+ def autoclean?
+ @autoclean
end
- def run
+ # Enumerate the targets available under {#target_dir}
+ def each_target
SnapperConfig.each_in_dir(config_dir) do |config|
dir = target_dir + config.name
if !dir.exist?
- Snapsync.warn "not synchronizing #{config.name}, there are no corresponding directory in #{target_dir}. Call snapsync init to create a proper target directory"
+ Snapsync.warn "no directory for configuration #{config.name} in #{target_dir}"
else
- target = LocalTarget.new(dir)
- if !target.enabled?
- Snapsync.warn "not synchronizing #{config.name}, it is disabled"
- next
- end
+ yield(LocalTarget.new(dir))
+ end
+ end
+ end
- LocalSync.new(config, target).sync
- if should_autoclean_target?(target)
- if target.cleanup
- Snapsync.info "running cleanup for #{config.name}"
- target.cleanup.cleanup(target)
- else
- Snapsync.info "#{target.sync_policy.class.name} policy set, no cleanup to do for #{config.name}"
- end
- else
- Snapsync.info "autoclean not set on #{config.name}"
- end
+ def run
+ each_target do |target|
+ if !target.enabled?
+ Snapsync.warn "not synchronizing to #{target.dir}, it is disabled"
+ next
end
+ Sync.new(config, target, autoclean: autoclean?).run
end
end
end
end