Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

There was a problem

You must be a member of this account.

This project is archived and is in readonly mode.

Added :environment options to config.gem

#209

This way we can specify which gems will be loaded in each environment. This is useful since we don't want ZenTest or ruby-debug running in production.

Usage:

config.gem "ZenTest", :environment => :test

config.gem "ruby-debug", :environment => [:development, :test]

Tests included.

Reported by José Valim · May 16th, 2008 @ 06:21 PM

State: invalid
Milestone: 2.1.1
Assigned to: Rick Rick
Importance: none

Activity

  1. José Valim
    José Valim

    Oh, if :environment is not sent, like:

    config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net"

    We have the default behaviour, i.e. the gem is loaded in all environments.

    May 16th, 2008 @ 06:26 PM

  2. Rick
    Rick
    • Milestone set to 2.1.1
    • State changed from new to open
    • Assigned user set to Rick

    Is there a reason you're using ENV['RAILS_ENV'] and not Rails.environment?

    May 16th, 2008 @ 06:48 PM

  3. José Valim
    José Valim

    Searching the code I had more results with ENV['RAILS_ENV'], so I've used that one. =)

    May 16th, 2008 @ 07:02 PM

  4. DHH
    DHH
    • State changed from open to invalid

    You can just do this in config/environments/test.rb:

    config.gem "ZenTest"

    Then it's only loaded in the test environment.

    May 18th, 2008 @ 11:38 AM

  5. Josh Goebel
    Josh Goebel
    • Tag set to patch, railties, tested

    Ok, i'm a bit confused... so I have something like:

    require 'ruby-debug' (or or could just as easily be other config.gem stuff)

    in my development.rb, since it isn't needed in production... so I'm setting up a new box and I do:

    rake gem:install

    And it blows up... because in production mode cache_classes is enabled... and it tries to load all the models (load_application_classes in init) before it can install the gems... so if I do something like reference a class in a model (such as MiniMagick) then rake dies with an initialized constant error for MiniMagick before the gem installer has a chance to install the gem.

    Am I missing something here?

    February 10th, 2009 @ 05:43 PM

  6. Josh Goebel
    Josh Goebel

    I should specify I'm really doing:

    RAILS_ENV="production" rake gem:install

    gem:install works fine when run in dev mode since cache_classes usually isn't turned on.

    February 10th, 2009 @ 05:43 PM

  7. Josh Goebel
    Josh Goebel
    • Tag changed from patch, railties, tested to 2.2.2, bug

    I'm thinking maybe the global variable that determine if rake gem:install is being run should turn off cache_classes by default?

    February 10th, 2009 @ 08:32 PM

  8. Donald Ball
    Donald Ball

    I see two advantages to this approach:

    1. It's somewhat drier when you have a gem that's used in more than one environment

    2. DHH's approach requires you to run rake gem:install for each environment to be sure you've got everything; it would be nice to be able to run it once across all environments

    August 14th, 2009 @ 03:38 AM