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
- .absolute_external_file?(file_name) ⇒ Boolean
- .file_name(file_path) ⇒ Object
- .file_path(file_name) ⇒ Object
- .from_name(file_name) ⇒ Object
- .from_path(file_path) ⇒ Object
Class Method Details
.absolute_external_file?(file_name) ⇒ Boolean
33 34 35 36 37 |
# File 'lib/rspec_tracer/source_file.rb', line 33 def absolute_external_file?(file_name) file_name.start_with?('/') && !file_name.start_with?(RSpecTracer.root) && File.file?(file_name) end |
.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 30 31 |
# File 'lib/rspec_tracer/source_file.rb', line 27 def file_path(file_name) return file_name if absolute_external_file?(file_name) File.(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.binread(file_path)) } end |