Class: ReactManifest::DependencyMap

Inherits:
Object
  • Object
show all
Defined in:
lib/react_manifest/dependency_map.rb

Overview

Wraps Scanner results into a queryable dependency map.

Used by react_manifest:analyze rake task and Reporter for diagnostics.

Examples:

result = ReactManifest::Scanner.new.scan(classifier.classify)
map    = ReactManifest::DependencyMap.new(result)
map.shared_files_for("users")      # => ["ux/components/...", ...]
map.controllers_using("ux/lib/api_helpers") # => ["users", "admin"]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scan_result) ⇒ DependencyMap

Returns a new instance of DependencyMap.



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/react_manifest/dependency_map.rb', line 14

def initialize(scan_result)
  @symbol_index      = scan_result.symbol_index
  @controller_usages = scan_result.controller_usages
  @warnings          = scan_result.warnings

  # Inverted index: shared_file → [controllers] for O(1) lookup
  @controllers_by_file = {}
  @controller_usages.each do |ctrl, files|
    files.each { |f| (@controllers_by_file[f] ||= []) << ctrl }
  end
end

Instance Attribute Details

#controller_usagesObject (readonly)

Returns the value of attribute controller_usages.



12
13
14
# File 'lib/react_manifest/dependency_map.rb', line 12

def controller_usages
  @controller_usages
end

#symbol_indexObject (readonly)

Returns the value of attribute symbol_index.



12
13
14
# File 'lib/react_manifest/dependency_map.rb', line 12

def symbol_index
  @symbol_index
end

#warningsObject (readonly)

Returns the value of attribute warnings.



12
13
14
# File 'lib/react_manifest/dependency_map.rb', line 12

def warnings
  @warnings
end

Instance Method Details

#all_symbolsObject

Symbols defined in shared dirs



37
38
39
# File 'lib/react_manifest/dependency_map.rb', line 37

def all_symbols
  @symbol_index.keys
end

#controllers_using(shared_file) ⇒ Object

Which controllers use a given shared file (O(1) via inverted index)



32
33
34
# File 'lib/react_manifest/dependency_map.rb', line 32

def controllers_using(shared_file)
  @controllers_by_file.fetch(shared_file, [])
end

Pretty-print for the analyze rake task



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/react_manifest/dependency_map.rb', line 42

def print_report
  puts "\n=== ReactManifest Dependency Analysis ===\n\n"

  puts "Shared Symbol Index (#{@symbol_index.size} symbols):"
  @symbol_index.each do |sym, file|
    # Strip non-printable/control characters to prevent terminal manipulation
    safe_sym  = sym.gsub(/[^\x20-\x7E]/, "?")
    safe_file = file.gsub(/[^\x20-\x7E]/, "?")
    puts "  #{safe_sym.ljust(40)} #{safe_file}"
  end

  puts "\nPer-Controller Usage:"
  @controller_usages.each do |ctrl, files|
    puts "\n  [#{ctrl}] (#{files.size} shared references)"
    files.each { |f| puts "    #{f}" }
    puts "    (none)" if files.empty?
  end

  unless @warnings.empty?
    puts "\nWarnings (#{@warnings.size}):"
    @warnings.each { |w| puts "#{w}" }
  end

  puts "\n"
end

#shared_files_for(controller_name) ⇒ Object

All shared files used by the given controller



27
28
29
# File 'lib/react_manifest/dependency_map.rb', line 27

def shared_files_for(controller_name)
  @controller_usages.fetch(controller_name, [])
end