Module: DeprecationToolkit::ReadWriteHelper

Included in:
Behaviors::CIRecordHelper, Behaviors::Record, Collector
Defined in:
lib/deprecation_toolkit/read_write_helper.rb

Instance Method Summary collapse

Instance Method Details

#read(test) ⇒ Object



10
11
12
13
14
15
# File 'lib/deprecation_toolkit/read_write_helper.rb', line 10

def read(test)
  deprecation_file = Bundler.root.join(recorded_deprecations_path(test))
  YAML.load(deprecation_file.read).fetch(test_name(test), [])
rescue Errno::ENOENT
  []
end

#write(deprecation_file, deprecations_to_record) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/deprecation_toolkit/read_write_helper.rb', line 17

def write(deprecation_file, deprecations_to_record)
  original_deprecations = deprecation_file.exist? ? YAML.load_file(deprecation_file) : {}
  updated_deprecations = original_deprecations.dup

  deprecations_to_record.each do |test, deprecation_to_record|
    if deprecation_to_record.any?
      updated_deprecations[test] = deprecation_to_record
    else
      updated_deprecations.delete(test)
    end
  end

  if updated_deprecations.any?
    if updated_deprecations != original_deprecations
      deprecation_file.dirname.mkpath
      deprecation_file.write(YAML.dump(updated_deprecations.sort.to_h))
    end
  elsif deprecation_file.exist?
    deprecation_file.delete
  end
end