lib/rsync_cron/options.rb in rsync_cron-1.0.8 vs lib/rsync_cron/options.rb in rsync_cron-1.1.0

- old
+ new

@@ -1,38 +1,27 @@ module RsyncCron class Options - BANDWITH_LIMIT = 5*1024 - DEFAULT = { - rsh: "ssh", - bwlimit: BANDWITH_LIMIT, - exclude: "'DfsrPrivate'" - } - FLAGS = %w[noatime verbose archive compress] + BW_LIMIT = 5*1024 + DEFAULT_FLAGS = %W[verbose archive compress rsh=ssh bwlimit=#{BW_LIMIT} exclude='DfsrPrivate'] - def initialize(data: DEFAULT, flags: FLAGS) - @data = data.to_h - @flags = flags.to_a + def initialize(flags = DEFAULT_FLAGS) + @flags = Array(flags.dup) end def to_s - [flags, data].compact.join(" ") + return if @flags.empty? + @flags.map { |flag| "--#{flag}" }.join(" ") end - def merge(opt) - @data = @data.merge(opt) + def <<(flags) + flags.split(",").each do |flag| + @flags << flag if supported?(flag) + end self end - private def flags - return if @flags.empty? - @flags.map { |flag| "--#{flag}" }.join(" ") - end - - private def data - return if @data.empty? - @data.reduce([]) do |acc, (opt, val)| - acc << "--#{opt}=#{val}" - end.join(" ") + private def supported?(flag) + %x[rsync --#{flag} 2>&1].match(/unknown option/).nil? end end end