Module: RSpecTracer::SourceFile

Defined in:
lib/rspec_tracer/source_file.rb

Constant Summary collapse

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

Class Method Summary collapse

Class Method Details

.file_name(file_path) ⇒ Object



23
24
25
# File 'lib/rspec_tracer/source_file.rb', line 23

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

.file_path(file_name) ⇒ Object



27
28
29
# File 'lib/rspec_tracer/source_file.rb', line 27

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

.from_name(file_name) ⇒ Object



19
20
21
# File 'lib/rspec_tracer/source_file.rb', line 19

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

.from_path(file_path) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/rspec_tracer/source_file.rb', line 9

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