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

#default_credentials

Methods included from Mixins::LogHelper

#class_name

Instance Method Details

#delete(resource) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/multi_sync/targets/local_target.rb', line 47

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

#filesObject



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

def files
  files = []

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

  directory.files.lazily.each { |file|

    pathname = Pathname.new(file.key)

    # directory
    next if pathname.directory?

    MultiSync.debug "Found RemoteResource:'#{pathname}' from #{class_name}:'#{File.join(connection.local_root, destination_dir)}'"

    files << MultiSync::RemoteResource.new(
      file: file,
      path_with_root: target_dir + destination_dir + pathname,
      path_without_root: pathname
    )

  }

  files
end

#upload(resource) ⇒ Object



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

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