Class: Snapsync::Sync

Inherits:
Object
  • Object
show all
Defined in:
lib/snapsync/sync.rb

Overview

Single-target synchronization

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, target, autoclean: nil) ⇒ Sync

Returns a new instance of Sync.



8
9
10
11
12
13
14
15
# File 'lib/snapsync/sync.rb', line 8

def initialize(config, target, autoclean: nil)
    @config = config
    @target = target
    @autoclean =
        if autoclean.nil? then target.autoclean?
        else autoclean
        end
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



4
5
6
# File 'lib/snapsync/sync.rb', line 4

def config
  @config
end

#targetObject (readonly)

Returns the value of attribute target.



6
7
8
# File 'lib/snapsync/sync.rb', line 6

def target
  @target
end

Instance Method Details

#autoclean?Boolean

Whether the 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

Returns:

  • (Boolean)


22
23
24
# File 'lib/snapsync/sync.rb', line 22

def autoclean?
    @autoclean
end

#runObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/snapsync/sync.rb', line 34

def run
    sync

    if autoclean?
        if target.cleanup
            Snapsync.info "running cleanup for #{target.dir}"
            target.cleanup.cleanup(target)
        else
            Snapsync.info "#{target.sync_policy.class.name} policy set, no cleanup to do for #{target.dir}"
        end
    else
        Snapsync.info "autoclean not set on #{target.dir}"
    end
end

#syncObject

The method that performs synchronization

One usually wants to call #run, which also takes care of running cleanup if #autoclean? is true



30
31
32
# File 'lib/snapsync/sync.rb', line 30

def sync
    LocalSync.new(config, target).sync
end