Module: Ftpmock::PutHelper

Defined in:
lib/ftpmock/helpers/put_helper.rb

Class Method Summary collapse

Class Method Details

.cached?(cache_path, remotefile) ⇒ Boolean

Returns:

  • (Boolean)


5
6
7
8
# File 'lib/ftpmock/helpers/put_helper.rb', line 5

def cached?(cache_path, remotefile)
  path = path_for(cache_path, remotefile)
  path.exist?
end

.compare(cache_path, localfile, remotefile) ⇒ Object

Array



20
21
22
23
24
25
26
# File 'lib/ftpmock/helpers/put_helper.rb', line 20

def compare(cache_path, localfile, remotefile)
  return [] unless cached?(cache_path, remotefile)

  path = path_for(cache_path, remotefile)
  diff = StringUtils.diff(localfile, path)
  diff.split("\n")
end

.exist?(localfile) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/ftpmock/helpers/put_helper.rb', line 10

def exist?(localfile)
  File.exist?(localfile)
end

.path_for(cache_path, remotefile) ⇒ Object

def expire(cache_path, remotefile)

path = path_for(cache_path, remotefile)
path.exist? && path.delete

end



33
34
35
36
37
# File 'lib/ftpmock/helpers/put_helper.rb', line 33

def path_for(cache_path, remotefile)
  path = cache_path.join('put')
  FileUtils.mkdir_p(path)
  path.join(remotefile.tr('/', '-'))
end

.write(cache_path, localfile, remotefile) ⇒ Object



14
15
16
17
# File 'lib/ftpmock/helpers/put_helper.rb', line 14

def write(cache_path, localfile, remotefile)
  path = path_for(cache_path, remotefile)
  FileUtils.cp(localfile, path)
end