moomerman-rambo 0.3 → 0.4.1
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/controller/cache.rb +17 -0
- data/lib/rambo/controller/params.rb +26 -0
- data/lib/rambo/controller/redirect.rb +13 -0
- data/lib/rambo/{templating.rb → controller/template.rb} +1 -1
- data/lib/rambo/controller.rb +24 -0
- data/lib/rambo/server.rb +1 -2
- metadata +9 -15
- data/lib/rambo/base_controller.rb +0 -71
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module Cache
|
|
2
|
+
def fresh?(model, options={})
|
|
3
|
+
@@etags ||= {}
|
|
4
|
+
etag = Digest::SHA1.hexdigest(model.inspect)
|
|
5
|
+
response.header['ETag'] = "\"#{etag}\""
|
|
6
|
+
response.header['Expires'] = (MooTime.now + options[:expires_in]).httpdate if options[:expires_in]
|
|
7
|
+
response.header['Cache-Control'] = 'public'
|
|
8
|
+
if @@etags[request.uri] == etag
|
|
9
|
+
response.status = 304
|
|
10
|
+
response.body = ''
|
|
11
|
+
return true
|
|
12
|
+
else
|
|
13
|
+
@@etags[request.uri] = etag
|
|
14
|
+
return false
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module Params
|
|
2
|
+
def params
|
|
3
|
+
if !self.request.params.keys.join.include?('[')
|
|
4
|
+
@params ||= indifferent_hash.merge(self.request.params)
|
|
5
|
+
else
|
|
6
|
+
@params ||= self.request.params.inject indifferent_hash do |res, (key,val)|
|
|
7
|
+
if key.include?('[')
|
|
8
|
+
head = key.split(/[\]\[]+/)
|
|
9
|
+
last = head.pop
|
|
10
|
+
head.inject(res){ |hash,k| hash[k] ||= indifferent_hash }[last] = val
|
|
11
|
+
else
|
|
12
|
+
res[key] = val
|
|
13
|
+
end
|
|
14
|
+
res
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
if request.path_components.size() > 2
|
|
18
|
+
@params.merge!(:id => request.path_components[3])
|
|
19
|
+
end
|
|
20
|
+
@params
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def indifferent_hash
|
|
24
|
+
Hash.new {|hash,key| hash[key.to_s] if Symbol === key }
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module Redirect
|
|
2
|
+
def redirect(destination, options={})
|
|
3
|
+
destination = destination.to_s if destination.is_a? Symbol
|
|
4
|
+
unless destination[0,1] == "/"
|
|
5
|
+
destination = "/#{self.controller}/#{destination}"
|
|
6
|
+
end
|
|
7
|
+
puts "redirecting to #{destination}"
|
|
8
|
+
|
|
9
|
+
response.status = 302
|
|
10
|
+
response.header['Location'] = destination
|
|
11
|
+
return ""
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require 'rambo/controller/template'
|
|
2
|
+
require 'rambo/controller/cache'
|
|
3
|
+
require 'rambo/controller/params'
|
|
4
|
+
require 'rambo/controller/redirect'
|
|
5
|
+
|
|
6
|
+
module Rambo
|
|
7
|
+
class Controller
|
|
8
|
+
attr_accessor :params, :request, :response
|
|
9
|
+
|
|
10
|
+
include Template
|
|
11
|
+
include Cache
|
|
12
|
+
include Params
|
|
13
|
+
include Redirect
|
|
14
|
+
|
|
15
|
+
def controller
|
|
16
|
+
self.request.controller
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def action
|
|
20
|
+
self.request.action
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
end
|
|
24
|
+
end
|
data/lib/rambo/server.rb
CHANGED
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:
|
|
4
|
+
version: 0.4.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Richard Taylor
|
|
@@ -13,24 +13,14 @@ date: 2009-04-17 00:00:00 -07:00
|
|
|
13
13
|
default_executable:
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
|
-
name:
|
|
16
|
+
name: thin
|
|
17
17
|
type: :runtime
|
|
18
18
|
version_requirement:
|
|
19
19
|
version_requirements: !ruby/object:Gem::Requirement
|
|
20
20
|
requirements:
|
|
21
21
|
- - ">="
|
|
22
22
|
- !ruby/object:Gem::Version
|
|
23
|
-
version: 0.
|
|
24
|
-
version:
|
|
25
|
-
- !ruby/object:Gem::Dependency
|
|
26
|
-
name: json
|
|
27
|
-
type: :runtime
|
|
28
|
-
version_requirement:
|
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
30
|
-
requirements:
|
|
31
|
-
- - ">="
|
|
32
|
-
- !ruby/object:Gem::Version
|
|
33
|
-
version: 1.1.2
|
|
23
|
+
version: 1.0.0
|
|
34
24
|
version:
|
|
35
25
|
description: rambo is an experimental ruby web framework
|
|
36
26
|
email: moomerman@gmail.com
|
|
@@ -44,13 +34,17 @@ files:
|
|
|
44
34
|
- README
|
|
45
35
|
- lib/rambo.rb
|
|
46
36
|
- lib/rambo
|
|
47
|
-
- lib/rambo/
|
|
37
|
+
- lib/rambo/controller.rb
|
|
38
|
+
- lib/rambo/controller
|
|
39
|
+
- lib/rambo/controller/template.rb
|
|
40
|
+
- lib/rambo/controller/cache.rb
|
|
41
|
+
- lib/rambo/controller/redirect.rb
|
|
42
|
+
- lib/rambo/controller/params.rb
|
|
48
43
|
- lib/rambo/lock.rb
|
|
49
44
|
- lib/rambo/server.rb
|
|
50
45
|
- lib/rambo/proxy.rb
|
|
51
46
|
- lib/rambo/request.rb
|
|
52
47
|
- lib/rambo/response.rb
|
|
53
|
-
- lib/rambo/templating.rb
|
|
54
48
|
- lib/rambo/time.rb
|
|
55
49
|
- lib/rambo/upload.rb
|
|
56
50
|
has_rdoc: false
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
load 'rambo/templating.rb'
|
|
2
|
-
|
|
3
|
-
module Rambo
|
|
4
|
-
class BaseController
|
|
5
|
-
include Templating
|
|
6
|
-
|
|
7
|
-
attr_accessor :params, :request, :response
|
|
8
|
-
|
|
9
|
-
def params
|
|
10
|
-
if !self.request.params.keys.join.include?('[')
|
|
11
|
-
@params ||= indifferent_hash.merge(self.request.params)
|
|
12
|
-
else
|
|
13
|
-
@params ||= self.request.params.inject indifferent_hash do |res, (key,val)|
|
|
14
|
-
if key.include?('[')
|
|
15
|
-
head = key.split(/[\]\[]+/)
|
|
16
|
-
last = head.pop
|
|
17
|
-
head.inject(res){ |hash,k| hash[k] ||= indifferent_hash }[last] = val
|
|
18
|
-
else
|
|
19
|
-
res[key] = val
|
|
20
|
-
end
|
|
21
|
-
res
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
if request.path_components.size() > 2
|
|
25
|
-
@params.merge!(:id => request.path_components[3])
|
|
26
|
-
end
|
|
27
|
-
@params
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def fresh?(model, options={})
|
|
31
|
-
@@etags ||= {}
|
|
32
|
-
etag = Digest::SHA1.hexdigest(model.inspect)
|
|
33
|
-
response.header['ETag'] = "\"#{etag}\""
|
|
34
|
-
response.header['Expires'] = (MooTime.now + options[:expires_in]).httpdate if options[:expires_in]
|
|
35
|
-
response.header['Cache-Control'] = 'public'
|
|
36
|
-
if @@etags[request.uri] == etag
|
|
37
|
-
response.status = 304
|
|
38
|
-
response.body = ''
|
|
39
|
-
return true
|
|
40
|
-
else
|
|
41
|
-
@@etags[request.uri] = etag
|
|
42
|
-
return false
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
def controller
|
|
47
|
-
self.request.controller
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
def action
|
|
51
|
-
self.request.action
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
def indifferent_hash
|
|
55
|
-
Hash.new {|hash,key| hash[key.to_s] if Symbol === key }
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def redirect(destination, options={})
|
|
59
|
-
destination = destination.to_s if destination.is_a? Symbol
|
|
60
|
-
unless destination[0,1] == "/"
|
|
61
|
-
destination = "/#{self.controller}/#{destination}"
|
|
62
|
-
end
|
|
63
|
-
puts "redirecting to #{destination}"
|
|
64
|
-
|
|
65
|
-
response.status = 302
|
|
66
|
-
response.header['Location'] = destination
|
|
67
|
-
return ""
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
end
|
|
71
|
-
end
|