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
# File 'lib/fasten/support/yaml.rb', line 6

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

#save_yaml(path) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/fasten/support/yaml.rb', line 22

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