Sha256: 8bbb51fdb3cd3bab229d30852e5c9fe4f7f82157ccf74a5872f7f89de8669f0b
Contents?: true
Size: 1.12 KB
Versions: 14
Compression:
Stored size: 1.12 KB
Contents
require 'yaml' module Fasten module Support module Yaml def load_yaml(path) items = YAML.safe_load(File.read(path)).each do |name, params| if params.is_a? String params = { after: params } elsif params.is_a? Hash transform_params(params) else params = {} end task name, params end log_info "Loaded #{items.count} tasks from #{path}" end 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 protected def transform_params(params) params.keys.each do |k| val = params[k] if val.is_a?(String) && (match = %r{^/(.+)/$}.match(val)) val = Regexp.new(match[1]) end params[k.to_sym] = val params.delete(k) end end end end end
Version data entries
14 entries across 14 versions & 1 rubygems