Module: Ftpmock::ListHelper
- Defined in:
- lib/ftpmock/helpers/list_helper.rb
Class Method Summary collapse
- .dump(data) ⇒ Object
- .load(string) ⇒ Object
- .new_list ⇒ Object
- .path_for(cache_path) ⇒ Object
- .read(cache_path, chdir, key) ⇒ Object
- .read_dataset(cache_path) ⇒ Object
- .write(cache_path, chdir, key, list) ⇒ Object
- .write_dataset(cache_path, dataset) ⇒ Object
Class Method Details
.dump(data) ⇒ Object
49 50 51 |
# File 'lib/ftpmock/helpers/list_helper.rb', line 49 def dump(data) Psych.dump(data) end |
.load(string) ⇒ Object
45 46 47 |
# File 'lib/ftpmock/helpers/list_helper.rb', line 45 def load(string) Psych.load(string) end |
.new_list ⇒ Object
41 42 43 |
# File 'lib/ftpmock/helpers/list_helper.rb', line 41 def new_list {} end |
.path_for(cache_path) ⇒ Object
33 34 35 36 37 38 39 |
# 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) ⇒ Object
7 8 9 10 11 |
# 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) ⇒ Object
21 22 23 24 25 |
# 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) ⇒ Object
13 14 15 16 17 18 19 |
# 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) ⇒ Object
27 28 29 30 31 |
# 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 |