Class: Rails::Worktrees::EnvBootstrapper
- Inherits:
-
Object
- Object
- Rails::Worktrees::EnvBootstrapper
- Defined in:
- lib/rails/worktrees/env_bootstrapper.rb
Overview
Creates or updates a worktree-local .env with deterministic defaults. rubocop:disable Metrics/ClassLength
Defined Under Namespace
Classes: Result
Constant Summary collapse
- ENV_FILE_NAME =
'.env'.freeze
- FILE_ENCODING =
'UTF-8'.freeze
Instance Method Summary collapse
- #call(dry_run: false) ⇒ Object
-
#initialize(target_dir:, worktree_name:, configuration:, peer_roots: nil) ⇒ EnvBootstrapper
constructor
A new instance of EnvBootstrapper.
- #preview ⇒ Object
Constructor Details
#initialize(target_dir:, worktree_name:, configuration:, peer_roots: nil) ⇒ EnvBootstrapper
Returns a new instance of EnvBootstrapper.
18 19 20 21 22 23 |
# File 'lib/rails/worktrees/env_bootstrapper.rb', line 18 def initialize(target_dir:, worktree_name:, configuration:, peer_roots: nil) @target_dir = target_dir @worktree_name = worktree_name @configuration = configuration @peer_roots = peer_roots.nil? ? nil : Array(peer_roots).compact end |
Instance Method Details
#call(dry_run: false) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/rails/worktrees/env_bootstrapper.rb', line 25 def call(dry_run: false) return disabled_result unless @configuration.bootstrap_env lines = existing_env_lines write_missing_updates(lines, resolved_values(lines), dry_run: dry_run) end |
#preview ⇒ Object
32 |
# File 'lib/rails/worktrees/env_bootstrapper.rb', line 32 def preview = result(false, [], resolved_values(existing_env_lines)) |