module DeprecationToolkit::ReadWriteHelper

Public Instance Methods

read(test) click to toggle source
# File lib/deprecation_toolkit/read_write_helper.rb, line 9
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) click to toggle source
# File lib/deprecation_toolkit/read_write_helper.rb, line 16
def write(deprecation_file, deprecations_to_record)
  create_deprecation_file(deprecation_file) unless deprecation_file.exist?

  content = YAML.load_file(deprecation_file)

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

  if content.any?
    deprecation_file.write(YAML.dump(content))
  else
    deprecation_file.delete
  end
end

Private Instance Methods

create_deprecation_file(deprecation_file) click to toggle source
# File lib/deprecation_toolkit/read_write_helper.rb, line 38
def create_deprecation_file(deprecation_file)
  deprecation_file.dirname.mkpath
  deprecation_file.write(YAML.dump({}))
end
recorded_deprecations_path(test) click to toggle source
# File lib/deprecation_toolkit/read_write_helper.rb, line 43
def recorded_deprecations_path(test)
  deprecation_folder = if Configuration.deprecation_path.is_a?(Proc)
    Configuration.deprecation_path.call(test_location(test))
  else
    Configuration.deprecation_path
  end

  path =
    if DeprecationToolkit::Configuration.test_runner == :rspec
      test.example_group.file_path.sub(%r{^./spec/}, "").sub(/_spec.rb$/, "")
    else
      test.class.name.underscore
    end

  Pathname(deprecation_folder).join("#{path}.yml")
end
test_location(test) click to toggle source
# File lib/deprecation_toolkit/read_write_helper.rb, line 60
def test_location(test)
  test.method(test_name(test)).source_location[0]
rescue NameError
  "unknown"
end
test_name(test) click to toggle source
# File lib/deprecation_toolkit/read_write_helper.rb, line 66
def test_name(test)
  if DeprecationToolkit::Configuration.test_runner == :rspec
    "test_" + test.full_description.underscore.squish.tr(" ", "_")
  else
    test.name
  end
end