Class: Kinksync::File2Sync

Inherits:
Object
  • Object
show all
Defined in:
lib/kinksync/file_2_sync.rb

Overview

Class that represents a duple of files with absolute path which can be synced

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ File2Sync

Configures a File2Sync class

Parameters:

  • file (String)

    local or remote file to sync



12
13
14
15
# File 'lib/kinksync/file_2_sync.rb', line 12

def initialize(file)
  @file = file
  @twin_file = twin_file(file)
end

Instance Method Details

#syncObject

Sync a file, copying origin over destination

Returns:

  • file or nil if file is already synced



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/kinksync/file_2_sync.rb', line 22

def sync
  if File.exist?(@twin_file) && FileUtils.identical?(@file, @twin_file)
    nil
  else
    origin = newer
    destination = twin_file(origin)
    FileUtils.mkdir_p(File.dirname(@twin_file))
    FileUtils.cp(origin, destination)
    @file
  end
end