Module: Ftpmock::GetHelper

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

Class Method Summary collapse

Class Method Details

.fetched?(localfile) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/ftpmock/helpers/get_helper.rb', line 34

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

.path_for(cache_path, remotefile) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/ftpmock/helpers/get_helper.rb', line 38

def path_for(cache_path, remotefile)
  path = cache_path.join('get')
  remotefile = PathHelper.simplify(remotefile)
  ret = path.join(remotefile)
  FileUtils.mkdir_p(ret.dirname.to_s)
  ret
end

.read(cache_path, chdir, remotefile, localfile) ⇒ Object

reads from cache to localfile

true/false



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/ftpmock/helpers/get_helper.rb', line 8

def read(cache_path, chdir, remotefile, localfile)
  # chdir =
  remotefile = PathHelper.join(PathHelper.simplify(chdir), remotefile).to_s
  # localfile = PathHelper.join(chdir, localfile).to_s

  cached_path = path_for(cache_path, remotefile)

  File.exist?(cached_path) && FileUtils.cp(cached_path, localfile)

  fetched?(localfile)
end

.write(cache_path, chdir, remotefile, localfile) ⇒ Object

writes to cache from localfile



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ftpmock/helpers/get_helper.rb', line 21

def write(cache_path, chdir, remotefile, localfile)
  return false unless File.exist?(localfile)

  # chdir =
  remotefile = PathHelper.join(PathHelper.simplify(chdir), remotefile).to_s
  # localfile = PathHelper.join(chdir, localfile).to_s

  cached_path = path_for(cache_path, remotefile)
  FileUtils.cp(localfile, cached_path)

  File.exist?(cached_path)
end