(environ)ment
(environ)ment adds methods for asking what's the value of ENV['RACK_ENV'].
Installation
Add this line to your application's Gemfile:
gem 'ment'And then execute:
$ bundleOr install it yourself as:
$ gem install mentUsage
Ment adds the following methods to your Rack app:
-
::environment/#environment: returns the value ofENV['RACK_ENV'] -
::development?/#development?: returnstrueifENV['RACK_ENV'] == 'development' -
::production?/#production?: returnstrueifENV['RACK_ENV'] == 'production' -
::staging?/#staging?: returnstrueifENV['RACK_ENV'] == 'staging' -
::test?/#test?: returnstrueifENV['RACK_ENV'] == 'test'
Using Ment directly
require 'ment'
proc = Proc.new do
if Ment.production?
[200, {}, ['This is production']]
else
[200, {}, ["The current environment is #{Ment.environment}"]]
end
end
run procUsing Rack
require 'ment'
class App
include Ment
def call(env)
if production?
[200, {}, ['This is production']]
else
[200, {}, ["The current environment is #{environment}"]]
end
end
end
run App.newUsing Cuba
require 'cuba'
require 'ment'
Cuba.plugin Ment
Cuba.define do
on production? do
res.write 'This is production'
end
on root do
res.write "The current environment is #{environment}"
end
endUsing Hobbit
require 'hobbit'
require 'ment'
class App < Hobbit::Base
include Ment
if production?
get '/' do
'This is production'
end
end
get '/' do
"The current environment is #{environment}"
end
endContributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request
License
See the LICENSE.