Class: Rsync

Inherits:
Object
  • Object
show all
Defined in:
lib/rsync_wrapper/rsync.rb

Instance Method Summary collapse

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
# 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].map{|ext| "*.#{ext}"} || []
  @exclusions = opts[:exclusions] || []
  if opts[:subdirs_only]
    @inclusions << '*/' # include subdirectories
    @exclusions << '*'
  end
  @logfile = opts[:log_dir] ? File.join(opts[:log_dir], "rsync-#{SecureRandom.uuid}.log") : opts[:logfile]
end

Instance Method Details

#sync!(&block) ⇒ Object



17
18
19
20
# File 'lib/rsync_wrapper/rsync.rb', line 17

def sync! &block
  exec_rsync
  parse_logfile &block
end