Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I reference a gemfile in a subdirectory/submodule?

Tags:

ruby

gemfile

I have two git modules A and B. B is a submodule (thus a subdirectory) of A. I have some ruby scripts in B that I need to call from A. Module A itself doesn't have any Ruby code (so no need for Gemfile). I have a Gemfile in B that lists the dependencies for the scripts in B. However to call these scripts from A I have to move the Gemfile up into A:

cd A
mv B/Gemfile .
bundle update
bundle install
bundle exec ruby B/someScript.rb

Is there a way I can call a script in B without having to first move the Gemfile up into A?

like image 918
tir38 Avatar asked Dec 08 '25 16:12

tir38


1 Answers

Simply move terminal to subfolder - B (submodule) and run the script. Anyhow A doesn't have any ruby code, so its fine to move terminal to B subfolder while running the script. That will be easy to manage submodule.

cd A/B
bundle update
bundle install
bundle exec ruby someScript.rb

If you really want it to be in A, then follow below Gemfile

Gemfile

# Gemfile inside project A
source 'http://rubygems.org/'

eval_gemfile File.join(File.dirname(__FILE__), "B/Gemfile")
like image 98
Sivalingam Avatar answered Dec 11 '25 10:12

Sivalingam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!