Class: ReactManifest::DependencyMap
- Inherits:
-
Object
- Object
- ReactManifest::DependencyMap
- Defined in:
- lib/react_manifest/dependency_map.rb
Overview
Instance Attribute Summary collapse
-
#controller_usages ⇒ Object
readonly
Returns the value of attribute controller_usages.
-
#symbol_index ⇒ Object
readonly
Returns the value of attribute symbol_index.
-
#warnings ⇒ Object
readonly
Returns the value of attribute warnings.
Instance Method Summary collapse
-
#all_symbols ⇒ Object
Symbols defined in shared dirs.
-
#controllers_using(shared_file) ⇒ Object
Which controllers use a given shared file (O(1) via inverted index).
-
#initialize(scan_result) ⇒ DependencyMap
constructor
A new instance of DependencyMap.
-
#print_report ⇒ Object
Pretty-print for the analyze rake task.
-
#shared_files_for(controller_name) ⇒ Object
All shared files used by the given controller.
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_usages ⇒ Object (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_index ⇒ Object (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 |
#warnings ⇒ Object (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_symbols ⇒ Object
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 |
#print_report ⇒ Object
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 |