Module: Appifier::Helpers::Datasets
- Defined in:
- lib/appifier/helpers/datasets.rb
Instance Method Summary collapse
- #check_dataset_defined?(template:) ⇒ Boolean
- #open_dataset(template:) ⇒ Object
- #open_yaml(filename:) ⇒ Object
- #write_dataset(template:, data:) ⇒ Object
Instance Method Details
#check_dataset_defined?(template:) ⇒ Boolean
16 17 18 |
# File 'lib/appifier/helpers/datasets.rb', line 16 def check_dataset_defined?(template:) return File::exist? File::("#{DEFAULT_DATASETS_PATH}/#{template}.yml") end |
#open_dataset(template:) ⇒ Object
6 7 8 9 10 11 12 13 14 |
# File 'lib/appifier/helpers/datasets.rb', line 6 def open_dataset(template:) path = File::("#{DEFAULT_DATASETS_PATH}/#{template}.yml") raise 'Dataset not found' unless File::exist? path begin return YAML.load_file(path) rescue StandardError => e raise e. end end |
#open_yaml(filename:) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/appifier/helpers/datasets.rb', line 25 def open_yaml(filename:) raise 'File not found' unless File::exist? filename begin return YAML.load_file(filename) rescue StandardError => e raise e. end end |
#write_dataset(template:, data:) ⇒ Object
20 21 22 23 |
# File 'lib/appifier/helpers/datasets.rb', line 20 def write_dataset(template:, data:) path = File::("#{DEFAULT_DATASETS_PATH}/#{template}.yml") File.open(path, 'w') { |file| file.write(data.to_yaml) } end |