forked from postrank-labs/goliath
/
goliath.rb
61 lines (54 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
61
require 'eventmachine'
require 'http/parser'
require 'async_rack'
require 'goliath/constants'
require 'goliath/version'
# The Goliath Framework
module Goliath
module_function
# Retrieves the current goliath environment
#
# @return [String] the current environment
def env
@env or fail "environment has not been set"
end
# Sets the current goliath environment
#
# @param [String|Symbol] the environment symbol
def env=(e)
es = case(e.to_sym)
when :dev then :development
when :prod then :production
else e.to_sym
end
@env = es
end
# Determines if we are in the production environment
#
# @return [Boolean] true if current environment is production, false otherwise
def prod?
env == :production
end
# Determines if we are in the development environment
#
# @return [Boolean] true if current environment is development, false otherwise
def dev?
env == :development
end
# Determines if we are in a custom environment
#
# @return [Boolean] true if current environment matches, false otherwise
def method_missing(name, *args)
if name[-1] == "?"
env == name[0..-2].to_sym
else
super
end
end
# Method missing implementation responds to predicate methods
#
# @return [Boolean] true if argument is a predicate method
def respond_to?(method)
method[-1] == "?" || super
end
end