Class: Rails::Worktrees::DatabaseConfigUpdater
- Inherits:
-
Object
- Object
- Rails::Worktrees::DatabaseConfigUpdater
- Defined in:
- lib/rails/worktrees/database_config_updater.rb
Overview
Safely patches common database.yml layouts for worktree suffixes.
Defined Under Namespace
Classes: Result
Constant Summary collapse
- SUFFIX_TEMPLATE =
"<%= ENV.fetch('WORKTREE_DATABASE_SUFFIX', '') %>".freeze
- SUPPORTED_ENVIRONMENTS =
%w[development test].freeze
- DATABASE_LINE_PATTERN =
/\A(\s*database:\s*)(.+?)(\s*(?:#.*)?\n?)\z/- SECTION_PATTERN =
/\A([A-Za-z0-9_]+):(?:\s|$)/
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(content:) ⇒ DatabaseConfigUpdater
constructor
A new instance of DatabaseConfigUpdater.
Constructor Details
#initialize(content:) ⇒ DatabaseConfigUpdater
Returns a new instance of DatabaseConfigUpdater.
16 17 18 |
# File 'lib/rails/worktrees/database_config_updater.rb', line 16 def initialize(content:) @content = content end |
Instance Method Details
#call ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rails/worktrees/database_config_updater.rb', line 20 def call state = { found: Hash.new(0), patched: 0, unsupported: [], environment: nil } lines = @content.lines.map.with_index { |line, index| patch_line(line, index, state) } Result.new( lines.join, state[:patched].positive?, (state[:found], state[:patched], state[:unsupported]) ) end |