Module: Fasten::Support::Yaml
- Included in:
- Runner
- Defined in:
- lib/fasten/support/yaml.rb
Instance Method Summary collapse
Instance Method Details
#load_yaml(path) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/fasten/support/yaml.rb', line 6 def load_yaml(path) items = YAML.safe_load(File.read(path)).each do |name, params| case params when String params = { after: params } when Hash transform_params(params) else params = {} end task name, **params end log_info "Loaded #{items.count} tasks from #{path}" end |
#save_yaml(path) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/fasten/support/yaml.rb', line 23 def save_yaml(path) keys = %i[after shell] items = tasks.map do |task| data = task.to_h.select do |key, _val| keys.include? key end [task.name, data] end.to_h File.write path, items.to_yaml log_info "Loaded #{items.count} tasks into #{path}" end |