Project

ment

0.0
No commit activity in last 3 years
No release in over 3 years
(environ)ment adds methods for asking what's the value of RACK_ENV.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

 Project Readme

(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 of ENV['RACK_ENV']
  • ::development?/#development?: returns true if ENV['RACK_ENV'] == 'development'
  • ::production?/#production?: returns true if ENV['RACK_ENV'] == 'production'
  • ::staging?/#staging?: returns true if ENV['RACK_ENV'] == 'staging'
  • ::test?/#test?: returns true if ENV['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

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

License

See the LICENSE.