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.
Files changed (3) hide show
  1. data/lib/rambo/env.rb +38 -26
  2. data/lib/rambo/request.rb +10 -2
  3. metadata +1 -1
data/lib/rambo/env.rb CHANGED
@@ -1,25 +1,32 @@
1
1
  module Rambo
2
2
  class Env
3
- @@config = {}
3
+ def self.config
4
+ @@config ||= YAML.load_file("config.yml") rescue nil
5
+ @@config ||= {}
6
+ end
4
7
 
5
8
  def initialize
6
- # TODO: config reload
7
- @@config ||= YAML.load_file("config.yml") rescue nil || {}
9
+ begin
10
+ # TODO: config reload
8
11
 
9
- if dbconf = @@config['datamapper']
10
- require 'dm-core'
11
- require 'dm-validations'
12
- require 'dm-timestamps'
13
- #DataMapper.setup(:default, 'mysql://localhost/moo_development')
14
- @@connection ||= DataMapper.setup(
15
- :default,
16
- :adapter => :mysql,
17
- :host => dbconf['host'],
18
- :database => dbconf['database'],
19
- :username => dbconf['username'],
20
- :password => dbconf['password']
21
- )
22
- @@dblogger ||= DataObjects::Mysql.logger = DataObjects::Logger.new(STDOUT, dbconf['logging']) if dbconf['logging']
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
- if cache = @@loadcache[file]
37
- return unless @@config['rambo']['reload_classes']
38
- if (mtime = File.mtime(file)) > cache
39
- puts "rambo: reloading: #{file}"
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
- else
44
- #puts "loading: #{file}"
45
- load file
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] || 'home'
33
+ path_components[1] || default_controller
26
34
  end
27
35
 
28
36
  def action
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moomerman-rambo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.6
4
+ version: 0.4.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Taylor