Awesome
(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:
$ bundle
Or install it yourself as:
$ gem install ment
Usage
Ment adds the following methods to your Rack app:
::environment
/#environment
: returns the value ofENV['RACK_ENV']
::development?
/#development?
: returnstrue
ifENV['RACK_ENV'] == 'development'
::production?
/#production?
: returnstrue
ifENV['RACK_ENV'] == 'production'
::staging?
/#staging?
: returnstrue
ifENV['RACK_ENV'] == 'staging'
::test?
/#test?
: returnstrue
ifENV['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 proc
Using 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.new
Using 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
end
Using 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
end
Contributing
- 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.