-
Notifications
You must be signed in to change notification settings - Fork 217
/
goliath.rb
60 lines (52 loc) · 1.37 KB
/
goliath.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
require 'eventmachine'
require 'http/parser'
require 'async_rack'
require 'goliath/constants'
require 'goliath/version'
# The Goliath Framework
module Goliath
module_function
ENVIRONMENTS = [:development, :production, :test, :staging]
# for example:
#
# def development?
# env? :development
# end
class << self
ENVIRONMENTS.each do |e|
define_method "#{e}?" do
warn "[DEPRECATION] `Goliath.#{e}?` is deprecated. Please use `Goliath.env?(#{e})` instead."
env? e
end
end
alias :prod? :production?
alias :dev? :development?
# Controls whether or not the application will be run using an at_exit block.
attr_accessor :run_app_on_exit
alias_method :run_app_on_exit?, :run_app_on_exit
end
# By default, we do run the application using the at_exit block.
self.run_app_on_exit = true
# Retrieves the current goliath environment
#
# @return [String] the current environment
def env
@env
end
# Sets the current goliath environment
#
# @param [String|Symbol] env the environment symbol
def env=(e)
@env = case(e.to_sym)
when :dev then :development
when :prod then :production
else e.to_sym
end
end
# Determines if we are in a particular environment
#
# @return [Boolean] true if current environment matches, false otherwise
def env?(e)
env == e.to_sym
end
end