sharp 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/sharp +1 -2
- data/lib/sharp.rb +38 -10
- data/lib/sharp/version.rb +1 -1
- data/sharp.gemspec +1 -1
- metadata +1 -1
data/bin/sharp
CHANGED
data/lib/sharp.rb
CHANGED
@@ -22,13 +22,14 @@ module Sharp
|
|
22
22
|
class Application
|
23
23
|
attr_reader :root, :router
|
24
24
|
|
25
|
-
def
|
26
|
-
|
25
|
+
def self.boot(root)
|
26
|
+
app = new(root)
|
27
|
+
app.boot
|
28
|
+
app
|
27
29
|
end
|
28
30
|
|
29
|
-
|
30
|
-
|
31
|
-
@logger ||= Logger.new(STDOUT)
|
31
|
+
def initialize(root)
|
32
|
+
@root = Pathname.new(root)
|
32
33
|
end
|
33
34
|
|
34
35
|
def boot
|
@@ -36,6 +37,7 @@ module Sharp
|
|
36
37
|
false
|
37
38
|
else
|
38
39
|
pre_boot
|
40
|
+
load_lib
|
39
41
|
load_models
|
40
42
|
load_actions
|
41
43
|
load_routes
|
@@ -52,6 +54,27 @@ module Sharp
|
|
52
54
|
@env ||= ENV['RACK_ENV'].present? ? ENV['RACK_ENV'].to_sym : :development
|
53
55
|
end
|
54
56
|
|
57
|
+
# TODO: Log to a file, command-line option for STDOUT
|
58
|
+
def logger
|
59
|
+
@logger ||= begin
|
60
|
+
logger = Logger.new(STDOUT)
|
61
|
+
logger.formatter = logger_formatter
|
62
|
+
logger
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def logger_formatter
|
67
|
+
@logger_formatter ||= proc do |severity, datetime, progname, msg|
|
68
|
+
color = case severity
|
69
|
+
when "ERROR" then '0;31'
|
70
|
+
when "WARN" then '1;33'
|
71
|
+
when "DEBUG" then '0;32'
|
72
|
+
else '1;37'
|
73
|
+
end
|
74
|
+
"\e[#{ color }m#{datetime} #{msg}\e[0;0m\n"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
55
78
|
#TODO: Pull out Sequel-specific code
|
56
79
|
def db
|
57
80
|
@db ||= begin
|
@@ -74,19 +97,24 @@ module Sharp
|
|
74
97
|
end
|
75
98
|
|
76
99
|
# TODO: Make an Array of load paths that you can add to that these are just part of
|
100
|
+
def load_lib
|
101
|
+
$:.unshift(root.join("app/lib"))
|
102
|
+
Dir.glob(root.join("app/lib/*.rb")) {|file| require file }
|
103
|
+
end
|
104
|
+
|
77
105
|
def load_models
|
78
|
-
$:.unshift(root.join("
|
79
|
-
Dir.glob(root.join("
|
106
|
+
$:.unshift(root.join("app/models"))
|
107
|
+
Dir.glob(root.join("app/models/*.rb")) {|file| require file }
|
80
108
|
end
|
81
109
|
|
82
110
|
def load_actions
|
83
111
|
Rack::Action.logger = logger
|
84
|
-
$:.unshift(root.join("
|
85
|
-
Dir.glob(root.join("
|
112
|
+
$:.unshift(root.join("app/actions"))
|
113
|
+
Dir.glob(root.join("app/actions/*.rb")) {|file| require file }
|
86
114
|
end
|
87
115
|
|
88
116
|
def load_routes
|
89
|
-
require "routes"
|
117
|
+
require File.expand_path "app/routes", root
|
90
118
|
end
|
91
119
|
|
92
120
|
def post_boot
|
data/lib/sharp/version.rb
CHANGED
data/sharp.gemspec
CHANGED