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 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/deprecation_toolkit/read_write_helper.rb', line 10 def read(test) deprecation_file = Bundler.root.join(recorded_deprecations_path(test)) data = YAML.load(deprecation_file.read) name = test_name(test) # Fast path: exact match return data[name] if data.key?(name) # Fallback: match by normalized name (handles tag addition/removal) normalized_name = normalized_test_name(name) return data[normalized_name] if data.key?(normalized_name) # Fallback: iterate over all normalized keys data.each do |key, deprecations| return deprecations if normalized_test_name(key) == normalized_name end [] rescue Errno::ENOENT [] end |
#write(deprecation_file, deprecations_to_record) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/deprecation_toolkit/read_write_helper.rb', line 32 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| # Remove any stale key that normalizes to the same name normalized = normalized_test_name(test) updated_deprecations.delete_if { |key, _| key != test && normalized_test_name(key) == normalized } 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 |