Class: Rails::Worktrees::ProjectConfigurationLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/rails/worktrees/project_configuration_loader.rb

Overview

Loads project-level configuration from the generated initializer without booting the full app.

Defined Under Namespace

Classes: AssignmentRecorder

Constant Summary collapse

CURRENT_WRAPPER_CALL =
'Rails.application.config.x.rails_worktrees.tap do |config|'.freeze
CONFIGURE_CALL =
'Rails::Worktrees.configure do |config|'.freeze
INITIALIZER_RELATIVE_PATH =
'config/initializers/rails_worktrees.rb'.freeze
KNOWN_GUARD_FRAGMENTS =
[
  "Gem.loaded_specs.key?('rails-worktrees')",
  'defined?(Rails::Worktrees)',
  'Rails::Worktrees.respond_to?(:configure)'
].freeze
TEMP_RAILS_ROOT_MUTEX =
Mutex.new

Instance Method Summary collapse

Constructor Details

#initialize(root:, configuration: Rails::Worktrees.configuration) ⇒ ProjectConfigurationLoader

Returns a new instance of ProjectConfigurationLoader.



17
18
19
20
# File 'lib/rails/worktrees/project_configuration_loader.rb', line 17

def initialize(root:, configuration: Rails::Worktrees.configuration)
  @root = root
  @configuration = configuration
end

Instance Method Details

#callObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rails/worktrees/project_configuration_loader.rb', line 22

def call
  return configuration unless initializer_path && File.file?(initializer_path)

  body = extract_configuration_body(File.read(initializer_path, encoding: 'UTF-8'))
  return configuration unless body

  recorder = AssignmentRecorder.new(configuration)

  with_temporary_rails_root do
    evaluate_configuration_body(body, recorder)
  end

  Rails::Worktrees.apply_application_configuration(recorder.values, configuration: configuration)
end