Module: Higan::Connector::ClassMethods

Defined in:
lib/higan/connector.rb

Instance Method Summary collapse

Instance Method Details

#connect(name, &block) ⇒ Object



4
5
6
# File 'lib/higan/connector.rb', line 4

def connect(name, &block)
  Session.new(**ftp_store[name], &block)
end

#test_ftp(name) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/higan/connector.rb', line 8

def test_ftp(name)
  config = ftp_store[name]

  Session.new(**config.to_h) { |ftp|
    raise Fail if ftp.closed?
    ftp.chdir(config.base_dir)
  }

  true
end

#test_uploading(name, dir_name = '') ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/higan/connector.rb', line 19

def test_uploading(name, dir_name = '')
  config = ftp_store[name]

  Session.new(**config.to_h) { |ftp|
    raise Fail if ftp.closed?
    ftp.chdir(config.base_dir)
    ftp.mkdir('_' + dir_name + '_' + DateTime.now.strftime('%Y%m%d_%H%M%S'))
  }

  true
end

#to(ftp_name, elements) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/higan/connector.rb', line 39

def to(ftp_name, elements)
  config = ftp_store[ftp_name]
  dirs = Set.new
  Session.new(**config.to_h) { |ftp, helper|
    elements.each do |target|
      target_path = config.remote_path(target.path)
      dir = File.dirname(target_path)
      unless dirs.include?(dir)
        helper.mkdir_p(dir)
        dirs.add(dir)
      end
      #ftp.chdir(dir)
      ftp.put(local_file_path(target.path), target_path)
    end
  }
end

#upload(name) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/higan/connector.rb', line 31

def upload(name)
  target = element_store[name]
  keys = target.element_list.map { |t| target.key(t.id) }
  elements = Uploading.where(key: keys)

  Uploader.new(elements)
end