Class: ReactManifest::DependencyMap
- Inherits:
-
Object
- Object
- ReactManifest::DependencyMap
- Includes:
- Logging
- 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.
Methods included from Logging
#log_debug, #log_info, #log_warn
Constructor Details
#initialize(scan_result) ⇒ DependencyMap
Returns a new instance of DependencyMap.
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/react_manifest/dependency_map.rb', line 16 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.
14 15 16 |
# File 'lib/react_manifest/dependency_map.rb', line 14 def controller_usages @controller_usages end |
#symbol_index ⇒ Object (readonly)
Returns the value of attribute symbol_index.
14 15 16 |
# File 'lib/react_manifest/dependency_map.rb', line 14 def symbol_index @symbol_index end |
#warnings ⇒ Object (readonly)
Returns the value of attribute warnings.
14 15 16 |
# File 'lib/react_manifest/dependency_map.rb', line 14 def warnings @warnings end |
Instance Method Details
#all_symbols ⇒ Object
Symbols defined in shared dirs
39 40 41 |
# File 'lib/react_manifest/dependency_map.rb', line 39 def all_symbols @symbol_index.keys end |
#controllers_using(shared_file) ⇒ Object
Which controllers use a given shared file (O(1) via inverted index)
34 35 36 |
# File 'lib/react_manifest/dependency_map.rb', line 34 def controllers_using(shared_file) @controllers_by_file.fetch(shared_file, []) end |
#print_report ⇒ Object
Pretty-print for the analyze rake task
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/react_manifest/dependency_map.rb', line 44 def print_report log_info "\n=== ReactManifest Dependency Analysis ===\n\n" log_info "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]/, "?") log_info " #{safe_sym.ljust(40)} #{safe_file}" end log_info "\nPer-Controller Usage:" @controller_usages.each do |ctrl, files| log_info "\n [#{ctrl}] (#{files.size} shared references)" files.each { |f| log_info " #{f}" } log_info " (none)" if files.empty? end unless @warnings.empty? log_info "\nWarnings (#{@warnings.size}):" @warnings.each { |w| log_warn " ⚠ #{w}" } end log_info "\n" end |
#shared_files_for(controller_name) ⇒ Object
All shared files used by the given controller
29 30 31 |
# File 'lib/react_manifest/dependency_map.rb', line 29 def shared_files_for(controller_name) @controller_usages.fetch(controller_name, []) end |