Class: MultiSync::LocalTarget

Inherits:
Target
  • Object
show all
Defined in:
lib/multi_sync/targets/local_target.rb

Instance Method Summary collapse

Methods inherited from Target

#initialize

Constructor Details

This class inherits a constructor from MultiSync::Target

Instance Method Details

#delete(resource) ⇒ Object



40
41
42
43
44
45
# File 'lib/multi_sync/targets/local_target.rb', line 40

def delete(resource)
  # MultiSync.say_status :delete, resource.path_with_root
  MultiSync.debug "Delete #{resource} '#{resource.path_without_root}' from #{self} '#{File.join(connection.local_root, destination_dir)}'"
  connection.directories.get(destination_dir.to_s).files.get(resource.path_without_root.to_s).destroy
  resource
end

#filesObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/multi_sync/targets/local_target.rb', line 10

def files
  files = []

  directory = connection.directories.get(destination_dir.to_s)
  return files if directory.nil?

  directory.files.each { |file|
    pathname = Pathname.new(file.key)

    # directory
    next if pathname.directory?
    files << MultiSync::RemoteResource.new(
      file: file,
      path_with_root: target_dir + destination_dir + pathname,
      path_without_root: pathname
    )
  }

  files.sort
end

#upload(resource) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/multi_sync/targets/local_target.rb', line 31

def upload(resource)
  # MultiSync.say_status :upload, resource.path_with_root
  MultiSync.debug "Upload #{resource} '#{resource.path_without_root}' to #{self} '#{File.join(connection.local_root, destination_dir)}'"
  directory = connection.directories.get(destination_dir.to_s)
  return if directory.nil?
  directory.files.create(key: resource.path_without_root.to_s, body: resource.body)
  resource
end