ramaze 0.3.9 → 0.3.9.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/ramaze/adapter.rb +16 -30
- data/lib/ramaze/adapter/base.rb +8 -6
- data/lib/ramaze/adapter/ebb.rb +0 -2
- data/lib/ramaze/adapter/mongrel.rb +0 -2
- data/lib/ramaze/adapter/scgi.rb +0 -2
- data/lib/ramaze/adapter/thin.rb +0 -2
- data/lib/ramaze/adapter/webrick.rb +0 -2
- data/lib/ramaze/contrib/facebook/facebook.rb +1 -1
- data/lib/ramaze/controller/resolve.rb +5 -3
- data/lib/ramaze/dispatcher.rb +1 -1
- data/lib/ramaze/dispatcher/action.rb +2 -1
- data/lib/ramaze/global.rb +3 -6
- data/lib/ramaze/global/globalstruct.rb +0 -5
- data/lib/ramaze/helper/partial.rb +17 -6
- data/lib/ramaze/spec/helper/browser.rb +15 -25
- data/lib/ramaze/version.rb +1 -1
- data/spec/examples/simple_auth.rb +32 -0
- data/spec/ramaze/helper/auth.rb +1 -1
- data/spec/ramaze/helper/flash.rb +1 -1
- data/spec/ramaze/helper/stack.rb +2 -0
- data/spec/ramaze/helper/user.rb +1 -1
- metadata +3 -2
data/lib/ramaze/adapter.rb
CHANGED
@@ -32,10 +32,10 @@ module Ramaze
|
|
32
32
|
start_adapter
|
33
33
|
|
34
34
|
Timeout.timeout(3) do
|
35
|
-
sleep 0.01 until Global.
|
35
|
+
sleep 0.01 until Global.server
|
36
36
|
end
|
37
37
|
|
38
|
-
Global.
|
38
|
+
Global.server.join unless Global.run_loose
|
39
39
|
|
40
40
|
rescue SystemExit
|
41
41
|
Ramaze.shutdown
|
@@ -44,25 +44,24 @@ module Ramaze
|
|
44
44
|
Ramaze.shutdown
|
45
45
|
end
|
46
46
|
|
47
|
-
# Takes Global.adapter and starts if test_connections is positive that
|
48
|
-
#
|
47
|
+
# Takes Global.adapter and starts if test_connections is positive that a
|
48
|
+
# connection can be made to the specified host and port.
|
49
49
|
# If you set Global.adapter to false it won't start any but deploy a
|
50
50
|
# dummy which is useful for testing purposes where you just send fake
|
51
51
|
# requests to Dispatcher.
|
52
52
|
|
53
53
|
def start_adapter
|
54
54
|
if adapter = Global.adapter
|
55
|
-
host,
|
55
|
+
host, port = Global.host, Global.port
|
56
56
|
|
57
57
|
if Global.test_connections
|
58
|
-
|
59
|
-
|
60
|
-
Log.info("and we're running: #{host}:#{ports}")
|
58
|
+
test_connection(host, port)
|
59
|
+
Log.info("Ramaze is ready to run on: #{host}:#{port}")
|
61
60
|
end
|
62
61
|
|
63
|
-
adapter.start(host,
|
62
|
+
adapter.start(host, port)
|
64
63
|
else # run dummy
|
65
|
-
Global.
|
64
|
+
Global.server = Thread.new{ sleep }
|
66
65
|
Log.warn("Seems like Global.adapter is turned off", "Continue without adapter.")
|
67
66
|
end
|
68
67
|
rescue LoadError => ex
|
@@ -73,34 +72,20 @@ module Ramaze
|
|
73
72
|
# them to finish, then goes on to kill them and exit still.
|
74
73
|
|
75
74
|
def shutdown
|
76
|
-
Timeout.timeout(
|
77
|
-
Global.
|
78
|
-
|
79
|
-
a.shutdown if a.respond_to?(:shutdown)
|
80
|
-
end
|
75
|
+
Timeout.timeout(3) do
|
76
|
+
a = Global.server[:adapter]
|
77
|
+
a.shutdown if a.respond_to?(:shutdown)
|
81
78
|
end
|
82
79
|
rescue Timeout::Error
|
83
|
-
Global.
|
80
|
+
Global.server.kill!
|
84
81
|
# Hard exit! because it won't be able to kill Webrick otherwise
|
85
82
|
exit!
|
86
83
|
end
|
87
84
|
|
88
|
-
# check the given host and ports via test_connection.
|
89
|
-
# Shuts down if no connection is possible.
|
90
|
-
|
91
|
-
def test_connections host, ports
|
92
|
-
ports.each do |port|
|
93
|
-
unless test_connection(host, port)
|
94
|
-
Log.error("Cannot open connection on #{host}:#{port}")
|
95
|
-
Ramaze.shutdown
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
85
|
# Opens a TCPServer temporarily and returns true if a connection is
|
101
86
|
# possible and false if none can be made
|
102
87
|
|
103
|
-
def test_connection
|
88
|
+
def test_connection(host, port)
|
104
89
|
Timeout.timeout(1) do
|
105
90
|
testsock = TCPServer.new(host, port)
|
106
91
|
testsock.close
|
@@ -108,7 +93,8 @@ module Ramaze
|
|
108
93
|
end
|
109
94
|
rescue => ex
|
110
95
|
Log.error(ex)
|
111
|
-
|
96
|
+
Log.error("Cannot open connection on #{host}:#{port}")
|
97
|
+
Ramaze.shutdown
|
112
98
|
end
|
113
99
|
end
|
114
100
|
end
|
data/lib/ramaze/adapter/base.rb
CHANGED
@@ -14,11 +14,9 @@ module Ramaze
|
|
14
14
|
# Afterwards adds a trap for the value of Global.shutdown_trap which
|
15
15
|
# calls Ramaze.shutdown when triggered (usually by SIGINT).
|
16
16
|
|
17
|
-
def start host,
|
18
|
-
|
19
|
-
|
20
|
-
trap(Global.shutdown_trap){ Ramaze.shutdown }
|
21
|
-
end
|
17
|
+
def start host, port
|
18
|
+
Global.server = run_server(host, port)
|
19
|
+
trap(Global.shutdown_trap){ Ramaze.shutdown }
|
22
20
|
end
|
23
21
|
|
24
22
|
# Does nothing
|
@@ -49,7 +47,11 @@ module Ramaze
|
|
49
47
|
# Then goes on and calls Dispatcher::handle with request and response.
|
50
48
|
|
51
49
|
def respond env
|
52
|
-
|
50
|
+
if Global.server == Thread.current
|
51
|
+
Thread.new{ Current.call(env) }.value
|
52
|
+
else
|
53
|
+
Current.call(env)
|
54
|
+
end
|
53
55
|
end
|
54
56
|
end
|
55
57
|
end
|
data/lib/ramaze/adapter/ebb.rb
CHANGED
data/lib/ramaze/adapter/scgi.rb
CHANGED
data/lib/ramaze/adapter/thin.rb
CHANGED
@@ -161,9 +161,11 @@ module Ramaze
|
|
161
161
|
ancestor <= Ramaze::Controller
|
162
162
|
} + Helper::LOOKUP.to_a
|
163
163
|
|
164
|
-
|
165
|
-
|
166
|
-
|
164
|
+
ancs.reverse.inject [] do |meths, anc|
|
165
|
+
meths +
|
166
|
+
anc.public_instance_methods(false).map{|im| im.to_s } -
|
167
|
+
anc.private_instance_methods(false).map{|im| im.to_s }
|
168
|
+
end
|
167
169
|
end
|
168
170
|
|
169
171
|
# Generate all possible permutations for given path.
|
data/lib/ramaze/dispatcher.rb
CHANGED
@@ -46,7 +46,7 @@ module Ramaze
|
|
46
46
|
Dispatcher::Error.process(error, meta)
|
47
47
|
end
|
48
48
|
|
49
|
-
#
|
49
|
+
# protects against recursive dispatch and reassigns the path_info in the
|
50
50
|
# request, the rest of the request is kept intact.
|
51
51
|
def dispatch_to(path)
|
52
52
|
if request.path_info == path
|
data/lib/ramaze/global.rb
CHANGED
@@ -8,9 +8,6 @@ module Ramaze
|
|
8
8
|
o "Set the adapter Ramaze will run on.",
|
9
9
|
:adapter => :webrick, :cli => [:webrick, :mongrel, :thin]
|
10
10
|
|
11
|
-
o "All running threads of Adapter will be collected here.",
|
12
|
-
:adapters => Set.new
|
13
|
-
|
14
11
|
o "Set the size of Backtrace shown.",
|
15
12
|
:backtrace_size => 10, :cli => 10
|
16
13
|
|
@@ -85,6 +82,9 @@ module Ramaze
|
|
85
82
|
o "Don't wait until all adapter-threads are finished or killed.",
|
86
83
|
:run_loose => false, :cli => false
|
87
84
|
|
85
|
+
o "The running server will be put here from Adapter.",
|
86
|
+
:server => nil
|
87
|
+
|
88
88
|
o "Turn on session for all requests.",
|
89
89
|
:sessions => true, :cli => true
|
90
90
|
|
@@ -97,9 +97,6 @@ module Ramaze
|
|
97
97
|
o "Interval in seconds of the background SourceReload",
|
98
98
|
:sourcereload => 3, :cli => 3
|
99
99
|
|
100
|
-
o "How many adapters Ramaze should spawn.",
|
101
|
-
:spawn => 1, :cli => 1, :short => :s
|
102
|
-
|
103
100
|
o "Test before start if adapters will be able to connect",
|
104
101
|
:test_connections => true, :cli => true
|
105
102
|
|
@@ -89,11 +89,6 @@ module Ramaze
|
|
89
89
|
cache = Ramaze.const_get(class_name)
|
90
90
|
end
|
91
91
|
|
92
|
-
# a range built from port and the number of spawns.
|
93
|
-
def ports
|
94
|
-
(port.to_i..(port.to_i + (spawn.to_i - 1)))
|
95
|
-
end
|
96
|
-
|
97
92
|
# reassigns the interval in the instance of SourceReload that is running or
|
98
93
|
# just waiting.
|
99
94
|
def sourcereload=(interval)
|
@@ -51,13 +51,24 @@ module Ramaze
|
|
51
51
|
options = { :controller => current.controller,
|
52
52
|
:instance => current.instance.dup }
|
53
53
|
|
54
|
-
|
55
|
-
|
56
|
-
if (
|
57
|
-
|
54
|
+
file = file.to_s
|
55
|
+
|
56
|
+
if Pathname(file).absolute?
|
57
|
+
file = file.squeeze '/'
|
58
|
+
unless File.exist?(file)
|
59
|
+
Log.warn "render_template: #{file} does not exist."
|
60
|
+
return ''
|
61
|
+
end
|
62
|
+
options[:template] = file
|
58
63
|
else
|
59
|
-
|
60
|
-
|
64
|
+
roots = [options[:controller].template_paths].flatten
|
65
|
+
|
66
|
+
if (files = Dir["{#{roots.join(',')}}"/"{#{file},#{file}.*}"]).any?
|
67
|
+
options[:template] = files.first.squeeze '/'
|
68
|
+
else
|
69
|
+
Log.warn "render_template: #{file} does not exist in the following directories: #{roots.join(',')}."
|
70
|
+
return ''
|
71
|
+
end
|
61
72
|
end
|
62
73
|
|
63
74
|
binding = options[:instance].scope
|
@@ -4,12 +4,11 @@
|
|
4
4
|
class Browser
|
5
5
|
attr_reader :cookie, :http
|
6
6
|
|
7
|
-
def initialize(
|
7
|
+
def initialize(base = '/', &block)
|
8
8
|
@base = base
|
9
9
|
@history = []
|
10
|
-
@
|
11
|
-
|
12
|
-
get url
|
10
|
+
@uri = URI("http://localhost:#{Ramaze::Global.port}")
|
11
|
+
@http = SimpleHttp.new(@uri)
|
13
12
|
|
14
13
|
story(&block) if block_given?
|
15
14
|
end
|
@@ -18,28 +17,28 @@ class Browser
|
|
18
17
|
instance_eval(&block) if block_given?
|
19
18
|
end
|
20
19
|
|
21
|
-
def get
|
22
|
-
request(:get,
|
20
|
+
def get path = '/', hash = {}
|
21
|
+
request(:get, path, hash)
|
23
22
|
end
|
24
23
|
|
25
|
-
def post
|
26
|
-
request(:post,
|
24
|
+
def post path = '/', hash = {}
|
25
|
+
request(:post, path, hash)
|
27
26
|
end
|
28
27
|
|
29
|
-
def erequest method,
|
30
|
-
response = request(method,
|
28
|
+
def erequest method, path, hash = {}
|
29
|
+
response = request(method, path, hash)
|
31
30
|
eval(response)
|
32
31
|
rescue Object => ex
|
33
32
|
p :response => response
|
34
33
|
ex.message
|
35
34
|
end
|
36
35
|
|
37
|
-
def epost
|
38
|
-
erequest(:post,
|
36
|
+
def epost path = '/', hash = {}
|
37
|
+
erequest(:post, path, hash)
|
39
38
|
end
|
40
39
|
|
41
|
-
def eget
|
42
|
-
erequest(:get,
|
40
|
+
def eget path = '/', hash = {}
|
41
|
+
erequest(:get, path, hash)
|
43
42
|
end
|
44
43
|
|
45
44
|
def hget(*args)
|
@@ -66,8 +65,8 @@ class Browser
|
|
66
65
|
end
|
67
66
|
end
|
68
67
|
|
69
|
-
def request method,
|
70
|
-
@http.uri =
|
68
|
+
def request method, path, hash = {}
|
69
|
+
@http.uri = @uri + "/#{@base}/#{path}".squeeze('/')
|
71
70
|
@http.request_headers['referer'] = @history.last.path rescue '/'
|
72
71
|
|
73
72
|
if method == :get and not hash.empty?
|
@@ -86,13 +85,4 @@ class Browser
|
|
86
85
|
@cookie = @http.response_headers['set-cookie']
|
87
86
|
@http.request_headers['cookie'] = @cookie
|
88
87
|
end
|
89
|
-
|
90
|
-
def url2uri url
|
91
|
-
uri = URI.parse(url)
|
92
|
-
uri.scheme = 'http'
|
93
|
-
uri.host = 'localhost'
|
94
|
-
uri.port = Ramaze::Global.port
|
95
|
-
uri.path = "/#{@base}/#{url}".squeeze('/')
|
96
|
-
uri
|
97
|
-
end
|
98
88
|
end
|
data/lib/ramaze/version.rb
CHANGED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec/helper'
|
2
|
+
require 'examples/simple_auth'
|
3
|
+
|
4
|
+
describe "SimpleAuth" do
|
5
|
+
behaves_like 'browser'
|
6
|
+
ramaze(:adapter => :webrick)
|
7
|
+
|
8
|
+
it 'should show start page' do
|
9
|
+
Browser.new do
|
10
|
+
http.basic_authentication "username", "password"
|
11
|
+
get('/').should == "Secret Info"
|
12
|
+
end
|
13
|
+
|
14
|
+
Browser.new do
|
15
|
+
http.basic_authentication "admin", "secret"
|
16
|
+
get('/').should == "Secret Info"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should not show start page' do
|
21
|
+
Browser.new do
|
22
|
+
lambda{ get('/') }.should.raise
|
23
|
+
end
|
24
|
+
|
25
|
+
Browser.new do
|
26
|
+
lambda do
|
27
|
+
http.basic_authentication "hello", "world"
|
28
|
+
lambda{ get('/') }.should.raise
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/spec/ramaze/helper/auth.rb
CHANGED
@@ -54,7 +54,7 @@ describe "StackHelper" do
|
|
54
54
|
].each do |controller|
|
55
55
|
|
56
56
|
it controller.to_s do
|
57
|
-
Browser.new(
|
57
|
+
Browser.new(Ramaze::Global.mapping.invert[controller]) do
|
58
58
|
get('/secured').should == ''
|
59
59
|
post('/login', 'username' => 'manveru', 'password' => 'password')
|
60
60
|
get('/secured').should == 'Secret content'
|
data/spec/ramaze/helper/flash.rb
CHANGED
data/spec/ramaze/helper/stack.rb
CHANGED
@@ -56,6 +56,7 @@ describe "StackHelper" do
|
|
56
56
|
|
57
57
|
it "indirect login" do
|
58
58
|
Browser.new do
|
59
|
+
get('/')
|
59
60
|
get('/foo').should == 'logged in'
|
60
61
|
get('/secure').should == 'secret content'
|
61
62
|
eget('/').should == {:logged_in => true}
|
@@ -64,6 +65,7 @@ describe "StackHelper" do
|
|
64
65
|
|
65
66
|
it "indirect login with params" do
|
66
67
|
Browser.new do
|
68
|
+
get('/')
|
67
69
|
eget('/bar', 'x' => 'y').should == {'x' => 'y'}
|
68
70
|
eget('/').should == {:logged_in => true}
|
69
71
|
end
|
data/spec/ramaze/helper/user.rb
CHANGED
@@ -36,7 +36,7 @@ describe Ramaze::Helper::User do
|
|
36
36
|
ramaze :adapter => :webrick
|
37
37
|
|
38
38
|
should 'login' do
|
39
|
-
Browser.new
|
39
|
+
Browser.new do
|
40
40
|
get('/status').should == 'false'
|
41
41
|
get('/login', 'name' => 'arthur', 'password' => '42')
|
42
42
|
get('/status').should == 'true'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ramaze
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.9
|
4
|
+
version: 0.3.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- manveru
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-03-
|
12
|
+
date: 2008-03-21 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -301,6 +301,7 @@ files:
|
|
301
301
|
- spec/examples/hello.rb
|
302
302
|
- spec/examples/linking.rb
|
303
303
|
- spec/examples/simple.rb
|
304
|
+
- spec/examples/simple_auth.rb
|
304
305
|
- spec/examples/templates
|
305
306
|
- spec/examples/templates/template_amrita2.rb
|
306
307
|
- spec/examples/templates/template_erubis.rb
|