module Ftpmock::ListHelper
Public Instance Methods
dump(data)
click to toggle source
# File lib/ftpmock/helpers/list_helper.rb, line 49 def dump(data) Psych.dump(data) end
load(string)
click to toggle source
# File lib/ftpmock/helpers/list_helper.rb, line 45 def load(string) Psych.load(string) end
new_list()
click to toggle source
# File lib/ftpmock/helpers/list_helper.rb, line 41 def new_list {} end
path_for(cache_path)
click to toggle source
# File lib/ftpmock/helpers/list_helper.rb, line 33 def path_for(cache_path) cache_path = PathHelper.clean(cache_path) cache_path.exist? || FileUtils.mkdir_p(cache_path) path = PathHelper.clean("#{cache_path}/list.yml") path.exist? || path.write(dump(new_list)) path end
read(cache_path, chdir, key)
click to toggle source
# File lib/ftpmock/helpers/list_helper.rb, line 7 def read(cache_path, chdir, key) key = PathHelper.join(chdir, key).to_s if chdir dataset = read_dataset(cache_path) dataset[key] end
read_dataset(cache_path)
click to toggle source
# File lib/ftpmock/helpers/list_helper.rb, line 21 def read_dataset(cache_path) path = path_for(cache_path) string = path.read load(string) end
write(cache_path, chdir, key, list)
click to toggle source
# File lib/ftpmock/helpers/list_helper.rb, line 13 def write(cache_path, chdir, key, list) key = PathHelper.join(chdir, key).to_s if chdir dataset = read_dataset(cache_path) dataset[key] = list write_dataset(cache_path, dataset) true end
write_dataset(cache_path, dataset)
click to toggle source
# File lib/ftpmock/helpers/list_helper.rb, line 27 def write_dataset(cache_path, dataset) path = path_for(cache_path) content = dump(dataset) path.write(content) end