Class: Woods::Extractors::ManagerExtractor

Inherits:
Object
  • Object
show all
Includes:
SharedDependencyScanner, SharedUtilityMethods
Defined in:
lib/woods/extractors/manager_extractor.rb

Overview

ManagerExtractor handles SimpleDelegator subclass extraction.

Manager/delegator objects wrap a model and provide a richer interface for specific contexts (e.g., OrderManager wrapping Order with checkout-specific methods). They live in ‘app/managers/`.

We extract:

  • Wrapped model (via SimpleDelegator superclass or initializer)

  • Public methods (the manager’s added interface)

  • Delegation chain (what gets delegated vs overridden)

  • Dependencies (what models/services they reference)

Examples:

extractor = ManagerExtractor.new
units = extractor.extract_all
order_mgr = units.find { |u| u.identifier == "OrderManager" }

Constant Summary collapse

MANAGER_DIRECTORIES =

Directories to scan for manager/delegator objects

%w[
  app/managers
].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

#initializeManagerExtractor

Returns a new instance of ManagerExtractor.



34
35
36
37
# File 'lib/woods/extractors/manager_extractor.rb', line 34

def initialize
  @directories = MANAGER_DIRECTORIES.map { |d| Rails.root.join(d) }
                                    .select(&:directory?)
end

Instance Method Details

#extract_allArray<ExtractedUnit>

Extract all manager/delegator objects

Returns:



42
43
44
45
46
47
48
# File 'lib/woods/extractors/manager_extractor.rb', line 42

def extract_all
  @directories.flat_map do |dir|
    Dir[dir.join('**/*.rb')].filter_map do |file|
      extract_manager_file(file)
    end
  end
end

#extract_manager_file(file_path) ⇒ ExtractedUnit?

Extract a single manager file

Parameters:

  • file_path (String)

    Path to the manager file

Returns:

  • (ExtractedUnit, nil)

    The extracted unit or nil if not a manager



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/woods/extractors/manager_extractor.rb', line 54

def extract_manager_file(file_path)
  source = File.read(file_path)
  class_name = extract_class_name(file_path, source, 'managers')

  return nil unless class_name
  return nil unless manager_file?(source)

  unit = ExtractedUnit.new(
    type: :manager,
    identifier: class_name,
    file_path: file_path
  )

  unit.namespace = extract_namespace(class_name)
  unit.source_code = annotate_source(source, class_name)
  unit. = (source, class_name)
  unit.dependencies = extract_dependencies(source, class_name)

  unit
rescue StandardError => e
  Rails.logger.error("Failed to extract manager #{file_path}: #{e.message}")
  nil
end