开发者

Rails: Per-environment initializers?

I'd like the code in one of my initializers (in config/initializers/) to be run only for the :development en开发者_C百科vironment, but not :test or :production. What's the best way to do that?

Pasting it into config/environments/test.rb seems unclean, and I don't quite like wrapping the entire initializer file in an if Rails.env == 'development' do ... end statement. Is there some canonical way to do this?

(Background: To speed up test load times, I'm trying to move the Barista gem into the :development group of my Gemfile, but config/initializers/barista_config.rb calls Barista.configure, so now it chokes on that in test (and production) mode.)


I'm pretty sure your only two options are putting the configuration code in config/environments/development.rb or wrapping your initializer code with your if block. You can tighten up your second option by doing if Rails.env.development?, though.


I don't know if this is a good idea, but it's a different idea.

You could create a config/initializers/development directory (or config/environments/development/initializers), put your barista_config.rb in that directory, and then include anything in that directory from config/environments/development.rb.

I don't know if that's a good idea or not but it's at least a third option...just in case you're still thinking about this problem three and a half years after asking the question.


Barista has a config setting for this:

Barista.configure do |c|
  c.env = :development
end

This will only recompile coffescript into js in dev mode and should speed up your tests.

Make sure you run:

rake barista:brew

before checking your code in.

https://github.com/Sutto/barista

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜