/
crepe.rb
70 lines (60 loc) 路 2 KB
/
crepe.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
62
63
64
65
66
67
68
69
70
ENV['CREPE_ENV'] ||= ENV['RACK_ENV'] ||= 'development'
ENV['CREPE_ROOT'] ||= Dir.pwd
require 'active_support/all'
# Crepe: the thin API stack.
module Crepe
autoload :Accept, 'crepe/accept'
autoload :API, 'crepe/api'
autoload :Config, 'crepe/config'
autoload :Endpoint, 'crepe/endpoint'
autoload :Filter, 'crepe/filter'
autoload :Helper, 'crepe/helper'
autoload :Middleware, 'crepe/middleware'
autoload :Params, 'crepe/params'
autoload :Parser, 'crepe/parser'
autoload :Renderer, 'crepe/renderer'
autoload :Request, 'crepe/request'
autoload :Response, 'crepe/response'
autoload :Streaming, 'crepe/streaming'
autoload :Util, 'crepe/util'
autoload :VERSION, 'crepe/version'
class << self
# Sets a custom {Logger}.
#
# Crepe.logger = Logger.new Crepe.root.join 'log', "#{Crepe.env}.log"
#
# @return [Logger] the assigned logger
attr_writer :logger
# Crepe's logging interface.
#
# Crepe.logger.debug 'testing: one, two, three...'
#
# @return [Logger] a centralized logger
# @see .logger=
def logger
@logger ||= Logger.new((STDOUT if Crepe.env.development?))
end
# The app's current environment. Defaults to "development" and can be
# overridden with an environment variable: either +CREPE_ENV+ or
# +RACK_ENV+.
#
# Crepe.env.production?
#
# @return [ActiveSupport::StringInquirer]
def env
@env ||= ActiveSupport::StringInquirer.new ENV['CREPE_ENV']
end
# A Pathname pointing to the app's root directory. Defaults to the working
# directory when the app was launched, but can be overridden with the
# +CREPE_ROOT+ environment variable.
#
# database_yml = Crepe.root 'config', 'database.yml'
# # => "/path/to/your/app/config/database.yml"
#
# @param [Array<String>] path a set of path components
# @return [Pathname]
def root *path
(@root ||= Pathname.new(ENV['CREPE_ROOT'])).join(*path)
end
end
end