Module: ReactManifest
- Defined in:
- lib/react_manifest.rb,
lib/react_manifest/logging.rb,
lib/react_manifest/railtie.rb,
lib/react_manifest/scanner.rb,
lib/react_manifest/version.rb,
lib/react_manifest/watcher.rb,
lib/react_manifest/reporter.rb,
lib/react_manifest/generator.rb,
lib/react_manifest/path_utils.rb,
lib/react_manifest/view_helpers.rb,
lib/react_manifest/ast_extractor.rb,
lib/react_manifest/configuration.rb,
lib/react_manifest/dependency_map.rb,
lib/react_manifest/layout_patcher.rb,
lib/react_manifest/tree_classifier.rb,
lib/react_manifest/symbol_extractor.rb,
lib/react_manifest/application_analyzer.rb,
lib/react_manifest/application_migrator.rb,
lib/react_manifest/sprockets_manifest_patcher.rb
Overview
rubocop:disable Metrics/ModuleLength
Defined Under Namespace
Modules: AstExtractor, Logging, PathUtils, SymbolExtractor, ViewHelpers, Watcher Classes: ApplicationAnalyzer, ApplicationMigrator, Configuration, DependencyMap, Generator, LayoutPatcher, Railtie, Reporter, Scanner, SprocketsManifestPatcher, TreeClassifier
Constant Summary collapse
- VERSION =
"0.2.34".freeze
Class Method Summary collapse
- .configuration ⇒ Object
- .configure {|configuration| ... } ⇒ Object
-
.invalidate_component_maps! ⇒ Object
Drop the cached component-symbol -> bundle map used by resolve_bundle_for_component / resolve_bundles_for_component(_direct).
- .reset! ⇒ Object
-
.resolve_bundle_for_component(component_name) ⇒ Object
Resolve a controller bundle from a React component symbol.
-
.resolve_bundles(ctrl_name) ⇒ Object
Returns the ordered list of bundle logical names for a given controller.
-
.resolve_bundles_for_component(component_name) ⇒ Object
Resolve all controller bundles needed for a React component symbol.
-
.resolve_bundles_for_component_direct(component_name) ⇒ Object
Resolve the direct bundle list needed for a React component symbol.
Class Method Details
.configuration ⇒ Object
24 25 26 |
# File 'lib/react_manifest.rb', line 24 def configuration @configuration ||= Configuration.new end |
.configure {|configuration| ... } ⇒ Object
28 29 30 |
# File 'lib/react_manifest.rb', line 28 def configure yield configuration end |
.invalidate_component_maps! ⇒ Object
Drop the cached component-symbol -> bundle map used by resolve_bundle_for_component / resolve_bundles_for_component(_direct). Unlike reset!, this does NOT touch the current Configuration — safe to call whenever ux/ files change (e.g. from the file watcher) so newly added controllers/components are picked up without losing app config.
43 44 45 |
# File 'lib/react_manifest.rb', line 43 def invalidate_component_maps! @component_maps_cache = nil end |
.reset! ⇒ Object
32 33 34 35 36 |
# File 'lib/react_manifest.rb', line 32 def reset! @configuration = nil @component_maps_cache = nil Scanner.clear_cache! end |
.resolve_bundle_for_component(component_name) ⇒ Object
Resolve a controller bundle from a React component symbol.
This is primarily used to support react-rails react_component calls,
where the requested component name is known and may not align 1:1 with
controller_path-derived bundle names.
82 83 84 |
# File 'lib/react_manifest.rb', line 82 def resolve_bundle_for_component(component_name) resolve_bundles_for_component_direct(component_name).last end |
.resolve_bundles(ctrl_name) ⇒ Object
Returns the ordered list of bundle logical names for a given controller. Used by the react_bundle_tag view helper.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/react_manifest.rb', line 49 def resolve_bundles(ctrl_name) config = configuration bundles = [] # 1. Shared bundle always first shared = resolve_bundle_reference(config, config.shared_bundle) bundles << shared if shared # 2. always_include bundles (e.g. ux_main) config.always_include.each do |b| resolved = resolve_bundle_reference(config, b) bundles << resolved if resolved && !bundles.include?(resolved) end # 3. Controller-specific bundle # Try fully-namespaced first: admin/users → ux_admin_users # Then drop segments: ux_admin controller_candidates(ctrl_name).each do |candidate| resolved = resolve_bundle_reference(config, candidate) if resolved && !bundles.include?(resolved) bundles << resolved break end end bundles end |
.resolve_bundles_for_component(component_name) ⇒ Object
Resolve all controller bundles needed for a React component symbol. Includes transitive controller-bundle dependencies inferred from component symbol usage across ux/app/* directories.
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/react_manifest.rb', line 114 def resolve_bundles_for_component(component_name) name = component_name.to_s return [] if name.empty? config = configuration maps = component_maps(config) root_bundle = maps[:symbol_to_bundle][name] return [] unless root_bundle ordered = [] visiting = Set.new visited = Set.new walk = lambda do |bundle_name| return if visited.include?(bundle_name) || visiting.include?(bundle_name) visiting << bundle_name maps[:bundle_dependencies].fetch(bundle_name, Set.new).each { |dep| walk.call(dep) } visiting.delete(bundle_name) visited << bundle_name ordered << bundle_name end walk.call(root_bundle) ordered.filter_map { |bundle_name| resolve_bundle_reference(config, bundle_name) } end |
.resolve_bundles_for_component_direct(component_name) ⇒ Object
Resolve the direct bundle list needed for a React component symbol. Returns shared first (if present), then the component's owning bundle.
Unlike resolve_bundles_for_component, this does not include transitive controller dependencies because generated controller manifests already inline those files via Sprockets require directives.
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/react_manifest.rb', line 92 def resolve_bundles_for_component_direct(component_name) name = component_name.to_s return [] if name.empty? config = configuration maps = component_maps(config) root_bundle = maps[:symbol_to_bundle][name] return [] unless root_bundle bundles = [] shared = resolve_bundle_reference(config, config.shared_bundle) bundles << shared if shared root = resolve_bundle_reference(config, root_bundle) bundles << root if root && !bundles.include?(root) bundles end |