The solution for the above problem is to have a different gemfile that you run your rails app against. It can be easily done by adding some terminal aliases to use a different gemfile file. I made that in the current configuration and it works well.
Last active
April 9, 2020 16:26
-
-
Save Chocksy/a00307aabfe96b684b92d5ffd471e3e7 to your computer and use it in GitHub Desktop.
Gemfile local that will allow for special gems only on local env
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ~/.gitignore_global | |
# Ignore Gemfile.local | |
/Gemfile.local | |
/Gemfile.local.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ~/.zshrc or ~/.bashrc | |
# this works to allow you to write commands like this: | |
# - $ be rails s # this will run the rails server using gemfile.local | |
# - $ be rspec spec # this will run rspec using gemfile.local | |
# - $ b # this will run bundle install but using gemfile.local | |
# if you run any of the usual commands then gemfile.local is ignored | |
alias restart_rails='kill -9 `cat tmp/pids/server.pid`; rails server -d' | |
alias kill_rails='kill -9 `cat tmp/pids/server.pid`' | |
__bundle_custom () { | |
if [ -f Gemfile.local ] | |
then | |
echo 'Doing regular bundle' | |
bundle $@ | |
echo 'Copy the regular gemfile.lock file to gemfile.local.lock' | |
__bundlelock_copy_to_local | |
echo 'Run bundle with gemfile.local' | |
BUNDLE_GEMFILE="Gemfile.local" bundle $@ | |
else | |
bundle $@ | |
fi | |
} | |
__bundle_exec_custom () { | |
if [ -f Gemfile.local ] | |
then | |
BUNDLE_GEMFILE="Gemfile.local" bundle exec $@ | |
else | |
bundle exec $@ | |
fi | |
} | |
__bundle_exec_rails_custom () { | |
if [ -f Gemfile.local ] | |
then | |
BUNDLE_GEMFILE="Gemfile.local" bundle exec rails $@ | |
else | |
bundle exec rails $@ | |
fi | |
} | |
__bundlelock_copy_to_local () { | |
if [ ! -f Gemfile.lock ] | |
then | |
echo "File Gemfile.lock does not exists" | |
exit 1 | |
fi | |
# copy file | |
cp Gemfile.lock Gemfile.local.lock | |
if [ $? != 0 ] | |
then | |
echo 'Problem copying file' | |
else | |
echo 'File copied successfully' | |
fi | |
} | |
# Rails aliases | |
alias b='__bundle_custom' | |
alias be='__bundle_exec_custom' | |
alias brails='__bundle_exec_rails_custom' | |
alias copy_local_lock='__bundlelock_copy_to_local' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Add this file in the root of your rails app. | |
gemfile = File.join(File.dirname(__FILE__), 'Gemfile') | |
if File.readable?(gemfile) | |
puts "Loading #{gemfile}..." if $DEBUG | |
instance_eval(File.read(gemfile)) | |
end | |
group :development,:test do | |
gem "binding_of_caller" | |
gem 'better_errors' | |
gem 'pry' | |
gem 'dotenv-rails' | |
gem "thin" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment