moomerman-rambo 0.4.6 → 0.4.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/rambo/env.rb +38 -26
- data/lib/rambo/request.rb +10 -2
- metadata +1 -1
data/lib/rambo/env.rb
CHANGED
|
@@ -1,25 +1,32 @@
|
|
|
1
1
|
module Rambo
|
|
2
2
|
class Env
|
|
3
|
-
|
|
3
|
+
def self.config
|
|
4
|
+
@@config ||= YAML.load_file("config.yml") rescue nil
|
|
5
|
+
@@config ||= {}
|
|
6
|
+
end
|
|
4
7
|
|
|
5
8
|
def initialize
|
|
6
|
-
|
|
7
|
-
|
|
9
|
+
begin
|
|
10
|
+
# TODO: config reload
|
|
8
11
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
12
|
+
if dbconf = Env.config['datamapper']
|
|
13
|
+
require 'dm-core'
|
|
14
|
+
require 'dm-validations'
|
|
15
|
+
require 'dm-timestamps'
|
|
16
|
+
#DataMapper.setup(:default, 'mysql://localhost/moo_development')
|
|
17
|
+
@@connection ||= DataMapper.setup(
|
|
18
|
+
:default,
|
|
19
|
+
:adapter => :mysql,
|
|
20
|
+
:host => dbconf['host'],
|
|
21
|
+
:database => dbconf['database'],
|
|
22
|
+
:username => dbconf['username'],
|
|
23
|
+
:password => dbconf['password']
|
|
24
|
+
)
|
|
25
|
+
@@dblogger ||= DataObjects::Mysql.logger = DataObjects::Logger.new(STDOUT, dbconf['logging']) if dbconf['logging']
|
|
26
|
+
end
|
|
27
|
+
rescue Exception => e
|
|
28
|
+
puts "Exception initializing environment: #{e.message}"
|
|
29
|
+
puts e.backtrace.join("\n")
|
|
23
30
|
end
|
|
24
31
|
|
|
25
32
|
Dir["controller/*.rb"].each { |x| funkyload x }
|
|
@@ -33,17 +40,22 @@ module Rambo
|
|
|
33
40
|
# request/response cycle
|
|
34
41
|
def funkyload(file)
|
|
35
42
|
@@loadcache ||= {}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
43
|
+
begin
|
|
44
|
+
if cache = @@loadcache[file]
|
|
45
|
+
return if Env.config['rambo'] and Env.config['rambo']['reload_classes'] == false
|
|
46
|
+
if (mtime = File.mtime(file)) > cache
|
|
47
|
+
puts "rambo: reloading: #{file}"
|
|
48
|
+
load file
|
|
49
|
+
@@loadcache[file] = mtime
|
|
50
|
+
end
|
|
51
|
+
else
|
|
52
|
+
#puts "rambo: loading: #{file}"
|
|
40
53
|
load file
|
|
41
|
-
@@loadcache[file] = mtime
|
|
54
|
+
@@loadcache[file] = File.mtime(file)
|
|
42
55
|
end
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
@@loadcache[file] = File.mtime(file)
|
|
56
|
+
rescue Exception => e
|
|
57
|
+
puts "Exception loading class [#{file}]: #{e.message}"
|
|
58
|
+
puts e.backtrace.join("\n")
|
|
47
59
|
end
|
|
48
60
|
end
|
|
49
61
|
|
data/lib/rambo/request.rb
CHANGED
|
@@ -20,9 +20,17 @@ module Rambo
|
|
|
20
20
|
def path_components
|
|
21
21
|
@path_components ||= path.split('/')
|
|
22
22
|
end
|
|
23
|
-
|
|
23
|
+
|
|
24
|
+
def default_controller
|
|
25
|
+
if Rambo::Env.config['rambo']
|
|
26
|
+
Rambo::Env.config['rambo']['default_controller'] || 'home'
|
|
27
|
+
else
|
|
28
|
+
'home'
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
24
32
|
def controller
|
|
25
|
-
path_components[1] ||
|
|
33
|
+
path_components[1] || default_controller
|
|
26
34
|
end
|
|
27
35
|
|
|
28
36
|
def action
|