Matthias
Matthias

Reputation: 4375

Install bundle of gem within other rails application

I have following setup:

a rails 4.0.0 application => my master application

through this application developers can create gem skeletons

now I´d like to create the gem skeleton source code and run bundle install of the gem Gemfile through a call in the rails master application:

class MyClass

  # this works
  def create_gem_skeleton
    path = "path-to-gem-skeleton-outside-the-rails-master-app"
    FileUtils.mkdir_p(path)
    `cd #{path} && bundle gem my-new-gem`
  end

  # this method gets called, after I created the gem skeleton and manipulated it a bit with my preferences
  def my_method
    path = "path-to-gem-skeleton-outside-the-rails-master-app"
    exec `cd #{path} && bundle install`   # does not work, installs always the rails master bundle inside my rails master application, never touches the new gem-skeleton
    system `cd #{path} && bundle install` # =||= .. same here
    `cd #{path} && bundle install`        # =||= .. same here

  end

end

Anybody an idea how I can run such a "bundle install" call within my rails master application, to install the bundle in the new gem-skeleton and not touch the rails bundle?

I use rails 4.0.0 and ruby 2.0.0-p195

Thanks!

Mat

Upvotes: 2

Views: 439

Answers (3)

Tim Moore
Tim Moore

Reputation: 9482

You should wrap your backticks calls in a block passed to Bundler.with_clean_env. This will ensure that it doesn't pick up your app's Gemfile:

Bundler.with_clean_env { `cd #{path} && bundle install` }

See the bundle-exec man page for details.

Upvotes: 8

Dominik Goltermann
Dominik Goltermann

Reputation: 4306

I think you have to touch your master bundle, at least to include your gem. when you bundle your master application, all gem dependencies are installed and locked into your master Gemfile.lock for dependency resolution.

Upvotes: 0

Benjamin Bouchet
Benjamin Bouchet

Reputation: 13181

Would it be a good solution for you to create a gem with dependencies?

The gem it self would not contain any particular code, but every time you need a new dependency you just have to modify its gemspec, and on other app simply run bundle update would update your gem and install its new dependencies.

Upvotes: 0

Related Questions