Search code examples
rubygemfile

Can I reference a gemfile in a subdirectory/submodule?


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?


Solution

  • 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")