sharp 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/sharp +0 -1
- data/lib/sharp.rb +46 -23
- data/lib/sharp/version.rb +1 -1
- data/sharp.gemspec +1 -1
- metadata +1 -1
data/bin/sharp
CHANGED
data/lib/sharp.rb
CHANGED
@@ -8,25 +8,25 @@ require "yaml"
|
|
8
8
|
module Sharp
|
9
9
|
|
10
10
|
class << self
|
11
|
+
attr_reader :app
|
11
12
|
delegate :logger, :boot, :root, :router, :env, :db, :to => :app
|
13
|
+
delegate :routes, :to => :router
|
12
14
|
end
|
13
15
|
|
14
|
-
def self.
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
@app = Application.new(*args, &init_routes)
|
19
|
-
end
|
16
|
+
def self.boot(root)
|
17
|
+
@app = Application.new(root)
|
18
|
+
@app.boot
|
19
|
+
@app
|
20
20
|
end
|
21
21
|
|
22
22
|
class Application
|
23
23
|
attr_reader :root, :router
|
24
24
|
|
25
|
-
def initialize(root
|
25
|
+
def initialize(root)
|
26
26
|
@root = Pathname.new(root)
|
27
|
-
@init_routes = init_routes
|
28
27
|
end
|
29
28
|
|
29
|
+
# TODO: Log to a file, command-line option for STDOUT
|
30
30
|
def logger
|
31
31
|
@logger ||= Logger.new(STDOUT)
|
32
32
|
end
|
@@ -35,25 +35,17 @@ module Sharp
|
|
35
35
|
if @booted
|
36
36
|
false
|
37
37
|
else
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
38
|
+
pre_boot
|
39
|
+
load_models
|
40
|
+
load_actions
|
41
|
+
load_routes
|
42
|
+
post_boot
|
43
|
+
finish_boot
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
-
def preboot
|
48
|
-
# A hook for plugins to add boot logic
|
49
|
-
db # TODO: Pull out Sequel-specific code
|
50
|
-
end
|
51
|
-
|
52
47
|
def router
|
53
|
-
@router ||=
|
54
|
-
boot
|
55
|
-
Rack::Router.new(&@init_routes)
|
56
|
-
end
|
48
|
+
@router ||= Rack::Router.new
|
57
49
|
end
|
58
50
|
|
59
51
|
def env
|
@@ -74,5 +66,36 @@ module Sharp
|
|
74
66
|
def db_config
|
75
67
|
@db_config ||= YAML.load_file(root.join("config/database.yml")).symbolize_keys[env].symbolize_keys
|
76
68
|
end
|
69
|
+
|
70
|
+
protected
|
71
|
+
def pre_boot
|
72
|
+
# A hook for plugins to add boot logic
|
73
|
+
db # TODO: Pull out Sequel-specific code
|
74
|
+
end
|
75
|
+
|
76
|
+
# TODO: Make an Array of load paths that you can add to that these are just part of
|
77
|
+
def load_models
|
78
|
+
$:.unshift(root.join("lib/models"))
|
79
|
+
Dir.glob(root.join("lib/models/*.rb")) {|file| require file }
|
80
|
+
end
|
81
|
+
|
82
|
+
def load_actions
|
83
|
+
Rack::Action.logger = logger
|
84
|
+
$:.unshift(root.join("lib/actions"))
|
85
|
+
Dir.glob(root.join("lib/actions/*.rb")) {|file| require file }
|
86
|
+
end
|
87
|
+
|
88
|
+
def load_routes
|
89
|
+
require "routes"
|
90
|
+
end
|
91
|
+
|
92
|
+
def post_boot
|
93
|
+
# A hook for plugins to add boot logic
|
94
|
+
end
|
95
|
+
|
96
|
+
def finish_boot
|
97
|
+
@booted = true
|
98
|
+
end
|
99
|
+
|
77
100
|
end
|
78
101
|
end
|
data/lib/sharp/version.rb
CHANGED
data/sharp.gemspec
CHANGED