Class: Woods::Extractors::RakeTaskExtractor
- Inherits:
-
Object
- Object
- Woods::Extractors::RakeTaskExtractor
- Includes:
- SharedDependencyScanner, SharedUtilityMethods
- Defined in:
- lib/woods/extractors/rake_task_extractor.rb
Overview
RakeTaskExtractor handles extraction of custom rake tasks from lib/tasks/.
Scans ‘lib/tasks/*/.rake` for task definitions and produces one ExtractedUnit per task. Uses static regex parsing (never evals rake files). Supports namespaced tasks, nested namespaces, task dependencies, and arguments.
Constant Summary collapse
- RAKE_DIRECTORIES =
%w[lib/tasks].freeze
- EXCLUDED_NAMESPACES =
Namespaces to exclude from extraction (this gem’s own tasks)
%w[woods].freeze
Constants included from SharedDependencyScanner
SharedDependencyScanner::FORM_ACTION_HELPER, SharedDependencyScanner::ROUTE_HELPER_PATTERN
Instance Method Summary collapse
-
#extract_all ⇒ Array<ExtractedUnit>
Extract all rake tasks from all discovered directories.
-
#extract_rake_file(file_path) ⇒ Array<ExtractedUnit>
Extract rake tasks from a single .rake file.
-
#initialize ⇒ RakeTaskExtractor
constructor
A new instance of RakeTaskExtractor.
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_initialize_params, #extract_namespace, #extract_parent_class, #extract_public_methods, #resolve_source_location, #skip_file?
Constructor Details
#initialize ⇒ RakeTaskExtractor
Returns a new instance of RakeTaskExtractor.
29 30 31 |
# File 'lib/woods/extractors/rake_task_extractor.rb', line 29 def initialize @directories = RAKE_DIRECTORIES.map { |d| Rails.root.join(d) }.select(&:directory?) end |
Instance Method Details
#extract_all ⇒ Array<ExtractedUnit>
Extract all rake tasks from all discovered directories.
36 37 38 39 40 |
# File 'lib/woods/extractors/rake_task_extractor.rb', line 36 def extract_all @directories.flat_map do |dir| Dir[dir.join('**/*.rake')].flat_map { |file| extract_rake_file(file) } end end |
#extract_rake_file(file_path) ⇒ Array<ExtractedUnit>
Extract rake tasks from a single .rake file.
Returns an Array because each file may contain multiple task definitions.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/woods/extractors/rake_task_extractor.rb', line 48 def extract_rake_file(file_path) return [] unless file_path.to_s.end_with?('.rake') source = File.read(file_path) tasks = parse_tasks(source) tasks.filter_map do |task_data| next if excluded_namespace?(task_data[:full_name]) build_unit(task_data, file_path, source) end rescue StandardError => e Rails.logger.error("Failed to extract rake tasks from #{file_path}: #{e.}") [] end |