Sha256: 5e0901a2f967b3d9be1f27a77c5ead859a5ce5739d70d6223008213bee212ec9
Contents?: true
Size: 1.84 KB
Versions: 1
Compression:
Stored size: 1.84 KB
Contents
module Lux class Environment ENVS ||= %w(development production test) def initialize env_name if env_name.empty? raise ArgumentError.new('RACK_ENV is not defined') # never default to "development", because it could be loaded as default in production elsif !ENVS.include?(env_name) raise ArgumentError.new('Unsupported environemt: %s (supported are %s)' % [env_name, ENVS]) end @env_name = env_name end def development? @env_name != 'production' end alias :dev? development? def production? @env_name == 'production' end alias :prod? :production? def test? $0.end_with?('/rspec') || @env_name == 'test' end def rake? $0.end_with?('/rake') end def live? value = ENV['LUX_LIVE'] || Lux.die('ENV LUX_LIVE not defined') value == 'true' end def local? !live? end def web? if @env_web.nil? list = ObjectSpace.each_object(Class).map(&:to_s) @env_web = list.include?('#<Class:Rack::Server>') || list.include?('Puma::Launcher') end @env_web end def cli? !web? end def cache? !no_cache? end def no_cache? @no_cache = ENV['LUX_ENV'].include?('c') if @no_cache.nil? @no_cache end def show_errors? @show_errors = ENV['LUX_ENV'].include?('e') if @show_errors.nil? @show_errors end def reload_code? @reload_code = ENV['LUX_ENV'].include?('r') if @reload_code.nil? @reload_code end def screen_log? @screen_log = ENV['LUX_ENV'].include?('l') if @screen_log.nil? @screen_log end ### # Lux.env == :dev def == what return true if what.to_s == @env_name send '%s?' % what end def to_s production? ? 'production' : 'development' end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
lux-fw-0.6.2 | ./lib/lux/environment/environment.rb |