class SourceFile
Source file and metadata
Public Class Methods
new(file)
click to toggle source
# File lib/cpp_dependency_graph/source_file.rb, line 5 def initialize(file) @path = file end
Public Instance Methods
basename()
click to toggle source
# File lib/cpp_dependency_graph/source_file.rb, line 9 def basename @basename ||= File.basename(@path) end
basename_no_extension()
click to toggle source
# File lib/cpp_dependency_graph/source_file.rb, line 13 def basename_no_extension @basename_no_extension ||= File.basename(@path, File.extname(@path)) end
header?()
click to toggle source
# File lib/cpp_dependency_graph/source_file.rb, line 21 def header? false # TODO: Implement check extension end
includes()
click to toggle source
# File lib/cpp_dependency_graph/source_file.rb, line 29 def includes @includes ||= all_includes end
loc()
click to toggle source
# File lib/cpp_dependency_graph/source_file.rb, line 33 def loc @loc ||= file_contents.lines.count end
parent_component()
click to toggle source
# File lib/cpp_dependency_graph/source_file.rb, line 25 def parent_component @parent_component ||= File.dirname(@path).split('/').last end
path()
click to toggle source
# File lib/cpp_dependency_graph/source_file.rb, line 17 def path @path ||= File.absolute_path(@path) end
Private Instance Methods
all_includes()
click to toggle source
# File lib/cpp_dependency_graph/source_file.rb, line 39 def all_includes @all_includes ||= scan_includes end
file_contents()
click to toggle source
# File lib/cpp_dependency_graph/source_file.rb, line 49 def file_contents @file_contents ||= sanitised_file_contents end
sanitised_file_contents()
click to toggle source
# File lib/cpp_dependency_graph/source_file.rb, line 53 def sanitised_file_contents contents = File.read(@path) return contents if contents.valid_encoding? contents.encode('UTF-16be', invalid: :replace, replace: '?').encode('UTF-8') end
scan_includes()
click to toggle source
# File lib/cpp_dependency_graph/source_file.rb, line 43 def scan_includes includes = file_contents.scan(/#include ["|<](.+)["|>]/) # TODO: use compiler lib to scan includes? llvm/clang? includes.uniq! includes.flatten end