Class: Woods::Extractors::RakeTaskExtractor

Inherits:
Object
  • Object
show all
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.

Examples:

extractor = RakeTaskExtractor.new
units = extractor.extract_all
cleanup = units.find { |u| u.identifier == "cleanup:stale_orders" }
cleanup.[:description] # => "Remove orders older than 30 days"

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

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

#initializeRakeTaskExtractor

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_allArray<ExtractedUnit>

Extract all rake tasks from all discovered directories.

Returns:



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.

Parameters:

  • file_path (String)

    Path to the .rake file

Returns:



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.message}")
  []
end