how would you set dynamically determined dependencies with or without bundler?

Discussion in 'Ruby' started by Jarmo Pertman, Jun 18, 2011.

  1. Hi!

    I have developing a gem where some of it's dependencies are not
    in .gemspec since they can be different depending of the value of
    environment variable, class variable or just depending of the OS in
    use. In short, these dependencies expose the same API, but can be
    switched during runtime before actually loading the gem itself. The
    gem then does something in the lines of:
    require "rubygems"
    gem "dependency", "version"
    require "dependency"

    depending of some criteria as written above. Now when using Bundler
    with it's Bundler.setup invocation, what should be in Gemfile so it
    would work the same on every configuration without having to have
    modified Gemfile and Gemfile.lock on each different machine.

    Can i have different "gem" lines in Gemfile on different machines and
    commit it actually into VCS without having to modify it on each and
    every machine separately?

    Something in the Gemfile like this would work perfectly?
    if RUBY_PLATFORM =~ /mswin|msys|mingw32/
    gem "dep1"
    else
    gem "dep2"
    end

    In that case "dep1" and "dep2" would end up in Gemfile.lock - is it
    okay, even if dep1 is not installable on unix platform?

    Jarmo Pertman
     
    Jarmo Pertman, Jun 18, 2011
    #1
    1. Advertisements

  2. After playing around a little i found this solution to be the one i
    needed - in Gemfile:

    platforms :mswin, :mingw do
    gem "win-specific-gem1"
    gem "win-specific-gem2"
    end

    gem "gem3" # works on all platforms

    Now in my gem i just do require "win-specific-gemX" if the OS is win
    and on other's require "gem3". If there's any better solution then let
    me know of course :)

    Jarmo Pertman
     
    Jarmo Pertman, Jun 18, 2011
    #2
    1. Advertisements

  3. unsubscribe
    =
     
    Kane Williams, Jun 18, 2011
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.