Improve how the sessions generator adds bcrypt
(#52346)
* doc: fix CHANGELOG message for sessions generator * fix: Sessions generator adds bcrypt more robustly Use Thor's `uncomment_lines` instead of `gsub_file`. If the Gemfile does not contain bcrypt, either commented or uncommented, then run `bundle add bcrypt`. Make sure all bundler commands run within `Bundler.with_original_env` to avoid bundler resolution problems while trying to resolve bundler dependencies. Typically the failure mode here is seeing: > Could not find bcrypt-3.1.20 in cached gems or installed locally (Bundler::GemNotFound) while bootstrapping the process that will run bundle-install or bundle-add.
This commit is contained in:
parent
d35f52c5d1
commit
f9e86f1bf5
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
|
|
||||||
# Generate with...
|
# Generate with...
|
||||||
bin/rails sessions
|
bin/rails generate sessions
|
||||||
|
|
||||||
# Generated files
|
# Generated files
|
||||||
app/models/current.rb
|
app/models/current.rb
|
||||||
|
@ -20,9 +20,12 @@ def configure_application
|
|||||||
end
|
end
|
||||||
|
|
||||||
def enable_bcrypt
|
def enable_bcrypt
|
||||||
# FIXME: Make more resilient in case the default comment has been removed
|
if File.read("Gemfile").include?('gem "bcrypt"')
|
||||||
gsub_file "Gemfile", /# gem "bcrypt"/, 'gem "bcrypt"'
|
uncomment_lines "Gemfile", /gem "bcrypt"/
|
||||||
execute_command :bundle, ""
|
Bundler.with_original_env { execute_command :bundle, "" }
|
||||||
|
else
|
||||||
|
Bundler.with_original_env { execute_command :bundle, "add bcrypt" }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_migrations
|
def add_migrations
|
||||||
|
Loading…
Reference in New Issue
Block a user