Class: Rails::Worktrees::ProcfileUpdater

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

Overview

Safely updates Procfile.dev to use the worktree-local DEV_PORT.

Defined Under Namespace

Classes: Result

Constant Summary collapse

STANDARD_WEB_ENTRY =
'web: env RUBY_DEBUG_OPEN=true bin/rails server -b 0.0.0.0 -p ${DEV_PORT:-3000}'.freeze
WEB_ENTRY_PATTERN =
/\Aweb:\s*.*\z/

Instance Method Summary collapse

Constructor Details

#initialize(content:) ⇒ ProcfileUpdater

Returns a new instance of ProcfileUpdater.



14
15
16
# File 'lib/rails/worktrees/procfile_updater.rb', line 14

def initialize(content:)
  @content = content
end

Instance Method Details

#callObject



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rails/worktrees/procfile_updater.rb', line 18

def call
  lines = @content.lines(chomp: true)
  web_entry_indexes = web_entry_indexes(lines)
  return skip_result if web_entry_indexes.empty?

  updated_content = rebuild_content(
    replace_web_entries(lines, web_entry_indexes),
    trailing_newline: @content.end_with?("\n")
  )

  build_result(updated_content)
end