Sha256: 72118217ee260a76a46bbc304be5c971f7107d71f518eb9fc3809767a223a6a3

Contents?: true

Size: 675 Bytes

Versions: 15

Compression:

Stored size: 675 Bytes

Contents

# frozen_string_literal: true

module RSpecTracer
  module SourceFile
    PROJECT_ROOT_REGEX = Regexp.new("^#{Regexp.escape(RSpecTracer.root)}").freeze

    module_function

    def from_path(file_path)
      return unless File.file?(file_path)

      {
        file_path: file_path,
        file_name: file_name(file_path),
        digest: Digest::MD5.hexdigest(File.read(file_path))
      }
    end

    def from_name(file_name)
      from_path(file_path(file_name))
    end

    def file_name(file_path)
      file_path.sub(PROJECT_ROOT_REGEX, '')
    end

    def file_path(file_name)
      File.expand_path(file_name.sub(%r{^/}, ''), RSpecTracer.root)
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
rspec-tracer-1.0.0 lib/rspec_tracer/source_file.rb
rspec-tracer-0.9.3 lib/rspec_tracer/source_file.rb
rspec-tracer-0.9.2 lib/rspec_tracer/source_file.rb
rspec-tracer-0.9.1 lib/rspec_tracer/source_file.rb
rspec-tracer-0.9.0 lib/rspec_tracer/source_file.rb
rspec-tracer-0.8.0 lib/rspec_tracer/source_file.rb
rspec-tracer-0.7.0 lib/rspec_tracer/source_file.rb
rspec-tracer-0.6.2 lib/rspec_tracer/source_file.rb
rspec-tracer-0.6.1 lib/rspec_tracer/source_file.rb
rspec-tracer-0.6.0 lib/rspec_tracer/source_file.rb
rspec-tracer-0.5.0 lib/rspec_tracer/source_file.rb
rspec-tracer-0.4.0 lib/rspec_tracer/source_file.rb
rspec-tracer-0.3.0 lib/rspec_tracer/source_file.rb
rspec-tracer-0.2.0 lib/rspec_tracer/source_file.rb
rspec-tracer-0.1.0 lib/rspec_tracer/source_file.rb