Class: Woods::Extractors::ViewComponentExtractor
- Inherits:
-
Object
- Object
- Woods::Extractors::ViewComponentExtractor
- Defined in:
- lib/woods/extractors/view_component_extractor.rb
Overview
ViewComponentExtractor handles ViewComponent extraction.
ViewComponent components are Ruby classes that encapsulate view logic. We can extract:
-
Slot definitions (renders_one, renders_many)
-
Sidecar template paths (.html.erb files next to the .rb file)
-
Initialize parameters (the component’s API)
-
Preview classes (ViewComponent::Preview subclasses)
-
Collection support
-
Callbacks (before_render, after_render)
-
Content areas (legacy API)
-
Component dependencies (rendered sub-components, model references)
Constant Summary
Constants included from RouteHelperResolver
RouteHelperResolver::IGNORED_HELPER_PREFIXES
Constants included from SharedDependencyScanner
SharedDependencyScanner::FORM_ACTION_HELPER, SharedDependencyScanner::ROUTE_HELPER_PATTERN
Instance Method Summary collapse
-
#extract_all ⇒ Array<ExtractedUnit>
Extract all ViewComponent components.
-
#extract_component(component) ⇒ ExtractedUnit?
Extract a single ViewComponent component.
-
#initialize ⇒ ViewComponentExtractor
constructor
A new instance of ViewComponentExtractor.
Methods included from RouteHelperResolver
#build_route_helper_map, #resolve_route_helper, #safe_rails_application_routes
Methods included from SharedDependencyScanner
#extract_constantize_targets, #scan_common_dependencies, #scan_form_dependencies, #scan_job_dependencies, #scan_mailer_dependencies, #scan_model_dependencies, #scan_navigation_dependencies, #scan_service_dependencies
Methods included from SharedUtilityMethods
#app_source?, #condition_label, #count_loc, #detect_entry_points, #extract_action_filter_actions, #extract_callback_conditions, #extract_class_methods, #extract_class_name, #extract_custom_errors, #extract_namespace, #extract_parent_class, #extract_public_methods, #resolve_source_location, #skip_file?
Constructor Details
#initialize ⇒ ViewComponentExtractor
Returns a new instance of ViewComponentExtractor.
32 33 34 35 |
# File 'lib/woods/extractors/view_component_extractor.rb', line 32 def initialize @component_base = find_component_base build_route_helper_map end |
Instance Method Details
#extract_all ⇒ Array<ExtractedUnit>
Extract all ViewComponent components
40 41 42 43 44 45 46 |
# File 'lib/woods/extractors/view_component_extractor.rb', line 40 def extract_all return [] unless @component_base @component_base.descendants.map do |component| extract_component(component) end.compact end |
#extract_component(component) ⇒ ExtractedUnit?
Extract a single ViewComponent component
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/woods/extractors/view_component_extractor.rb', line 52 def extract_component(component) return nil if component.name.nil? return nil if preview_class?(component) unit = ExtractedUnit.new( type: :view_component, identifier: component.name, file_path: source_file_for(component) ) # Skip components with no resolvable source file (framework/internal) return nil unless unit.file_path unit.source_code = read_source(unit.file_path) unit.namespace = extract_namespace(component) unit. = (component, unit.source_code) unit.dependencies = extract_dependencies(component, unit.source_code) unit rescue StandardError => e Rails.logger.error("Failed to extract view component #{component.name}: #{e.}") nil end |