Class: Docit::SystemGraph::SourceScanner
- Inherits:
-
Object
- Object
- Docit::SystemGraph::SourceScanner
- Defined in:
- lib/docit/system_graph/source_scanner.rb
Constant Summary collapse
- SOURCE_TYPES =
{ "app/services" => "service", "app/jobs" => "job", "app/mailers" => "mailer" }.freeze
Instance Method Summary collapse
-
#initialize(root:, excluded_paths: Docit.configuration.system_graph_excluded_paths) ⇒ SourceScanner
constructor
A new instance of SourceScanner.
- #references_for(path, candidates) ⇒ Object
- #source_nodes ⇒ Object
Constructor Details
#initialize(root:, excluded_paths: Docit.configuration.system_graph_excluded_paths) ⇒ SourceScanner
Returns a new instance of SourceScanner.
12 13 14 15 |
# File 'lib/docit/system_graph/source_scanner.rb', line 12 def initialize(root:, excluded_paths: Docit.configuration.system_graph_excluded_paths) @root = root @excluded_paths = excluded_paths.map(&:to_s) end |
Instance Method Details
#references_for(path, candidates) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/docit/system_graph/source_scanner.rb', line 33 def references_for(path, candidates) return [] unless path && File.exist?(full_path(path)) content = File.read(full_path(path)) candidates.select do |candidate| content.match?(/\b#{Regexp.escape(candidate)}\b/) end end |
#source_nodes ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/docit/system_graph/source_scanner.rb', line 17 def source_nodes SOURCE_TYPES.each_with_object([]) do |(dir, type), nodes| scan_dir(dir).each do |path| relative = relative_path(path) label = constant_name(relative, dir) nodes << Node.new( id: node_id(type, label), type: type, label: label, file: relative, metadata: { path: relative } ) end end end |