Setting the environment in Gemfile for bundling in

2019-03-22 06:56发布

hi, all I build a sinatra app, the main files for bundling as the following,

environment.rb

require 'sinatra'
require 'sequel'

ENV['RACK_ENV'] = 'development'

configure :production do
     #do something
end

configure :development, :test do
     #do something
end

Gemfile

gem 'sinatra'
gem 'sequel'

gem 'pg', :group => :production
gem 'sqlite3', :group => [:development, :test]

So, how to let the bundle install based on the ENV['RACK_ENV'] in my environment.rb file.

1条回答
在下西门庆
2楼-- · 2019-03-22 07:42

When doing a bundler require you can specify which groups to be required.

For example:

require 'rubygems'
require 'bundler'

if ENV['RACK_ENV'] == 'development'
  Bundler.require(:default, :development)
else
  Bundler.require(:default)
require 'sinatra'

More info on the bundler site gemfile specifications found here.

查看更多
登录 后发表回答