Class: Woods::Extractors::ConfigurationExtractor

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

Overview

ConfigurationExtractor handles Rails configuration file extraction.

Scans ‘config/initializers/` and `config/environments/` for Ruby configuration files. Each file becomes one ExtractedUnit with metadata about config type, gem references, and detected settings.

Examples:

extractor = ConfigurationExtractor.new
units = extractor.extract_all
devise = units.find { |u| u.identifier == "initializers/devise.rb" }

Constant Summary collapse

CONFIG_DIRECTORIES =

Directories to scan for configuration files

%w[
  config/initializers
  config/environments
].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

#initializeConfigurationExtractor

Returns a new instance of ConfigurationExtractor.



30
31
32
33
# File 'lib/woods/extractors/configuration_extractor.rb', line 30

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

Instance Method Details

#extract_allArray<ExtractedUnit>

Extract all configuration files and the behavioral profile.

Returns:



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/woods/extractors/configuration_extractor.rb', line 38

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

  profile = BehavioralProfile.new.extract
  units << profile if profile

  units
rescue StandardError => e
  Rails.logger.error("BehavioralProfile integration failed: #{e.message}")
  units || []
end

#extract_configuration_file(file_path) ⇒ ExtractedUnit?

Extract a single configuration file

Parameters:

  • file_path (String)

    Path to the configuration file

Returns:



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/woods/extractors/configuration_extractor.rb', line 58

def extract_configuration_file(file_path)
  source = File.read(file_path)
  identifier = build_identifier(file_path)
  config_type = detect_config_type(file_path)

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

  unit.namespace = config_type
  unit.source_code = annotate_source(source, identifier, config_type)
  unit. = (source, config_type)
  unit.dependencies = extract_dependencies(source)

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