Class: Rsync
- Inherits:
-
Object
- Object
- Rsync
- Defined in:
- lib/rsync_wrapper/rsync.rb
Instance Method Summary collapse
-
#initialize(**opts) ⇒ Rsync
constructor
A new instance of Rsync.
- #sync!(&block) ⇒ Object
Constructor Details
#initialize(**opts) ⇒ Rsync
Returns a new instance of Rsync.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rsync_wrapper/rsync.rb', line 2 def initialize **opts @dirs = {} [:src_dir, :dest_dir].each do |k| raise ArgumentError, "#{k} is required" unless opts[k] @dirs[k] = opts[k] end @inclusions = opts[:include_extensions] ? opts[:include_extensions].map{|ext| "*.#{ext}"} : [] @exclusions = opts[:exclusions] || [] if opts[:subdirs_only] @inclusions << '*/' # include subdirectories @exclusions << '*' end @logfile = if opts[:log_dir] File.join(opts[:log_dir], "rsync-#{SecureRandom.uuid}.log") elsif opts[:logfile] opts[:logfile] else File.join(Dir.pwd, "rsync-#{SecureRandom.uuid}.log") end @optional_arguments = [ :bwlimit, # TODO: add rsync's other arguments that wouldn't interfere with the design of this gem https://linux.die.net/man/1/rsync ].map{|arg| opts[arg] ? [arg, opts[arg]] : nil}.compact.to_h end |
Instance Method Details
#sync!(&block) ⇒ Object
28 29 30 31 |
# File 'lib/rsync_wrapper/rsync.rb', line 28 def sync! &block exec_rsync parse_logfile &block end |