schmobile 0.0.6 → 0.0.8
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/VERSION +1 -1
- data/lib/rack/schmobile.rb +18 -7
- data/schmobile.gemspec +1 -1
- data/test/test_schmobile.rb +6 -6
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.8
|
data/lib/rack/schmobile.rb
CHANGED
@@ -39,7 +39,7 @@ module Rack
|
|
39
39
|
request = Rack::Request.new(env)
|
40
40
|
|
41
41
|
if is_mobile_session?(env, request) && redirect?(request)
|
42
|
-
return [ 301, { "Location" =>
|
42
|
+
return [ 301, { "Location" => redirect_location(request) }, [] ]
|
43
43
|
end
|
44
44
|
|
45
45
|
@app.call(env)
|
@@ -64,16 +64,27 @@ module Rack
|
|
64
64
|
# Returns true if this middleware has been configured with a redirect_to and the requested path is not already
|
65
65
|
# below the configured redirect_to
|
66
66
|
def redirect?(request)
|
67
|
-
|
68
|
-
|
67
|
+
redirecting = true
|
68
|
+
|
69
|
+
if @options.key?(:redirect_if)
|
70
|
+
redirecting = @options[:redirect_if].call(request)
|
71
|
+
end
|
72
|
+
|
73
|
+
if @options.key?(:redirect_to)
|
74
|
+
redirecting &&= request.path !~ /^#{@options[:redirect_to]}/
|
75
|
+
else
|
76
|
+
redirecting = false
|
69
77
|
end
|
70
78
|
|
71
|
-
|
79
|
+
redirecting
|
80
|
+
end
|
81
|
+
|
82
|
+
def redirect_location(request)
|
83
|
+
"#{@options[:redirect_to]}#{redirect_with(request)}"
|
72
84
|
end
|
73
85
|
|
74
|
-
def
|
75
|
-
|
76
|
-
build_path(destination, request)
|
86
|
+
def redirect_with(request)
|
87
|
+
build_path(@options[:redirect_with].to_s, request)
|
77
88
|
end
|
78
89
|
|
79
90
|
private
|
data/schmobile.gemspec
CHANGED
data/test/test_schmobile.rb
CHANGED
@@ -44,7 +44,7 @@ class TestSchmobile < Test::Unit::TestCase
|
|
44
44
|
end
|
45
45
|
|
46
46
|
should "return an HTTP permanent redirect when given a redirect path and used by a mobile client" do
|
47
|
-
@rack.
|
47
|
+
@rack = Rack::Schmobile.new(@app, :redirect_to => "/hello")
|
48
48
|
@rack.expects(:is_mobile_session?).returns(true)
|
49
49
|
|
50
50
|
assert_equal [301, {"Location"=>"/hello"}, []], @rack.call(environment)
|
@@ -126,20 +126,20 @@ class TestSchmobile < Test::Unit::TestCase
|
|
126
126
|
end
|
127
127
|
|
128
128
|
should "return false when :if resolves to false" do
|
129
|
-
@rack = Rack::Schmobile.new(@app, :
|
129
|
+
@rack = Rack::Schmobile.new(@app, :redirect_to => "/wonderland", :redirect_if => Proc.new { |request| false })
|
130
130
|
assert !@rack.redirect?(request("PATH_INFO" => "/somewhere"))
|
131
131
|
end
|
132
132
|
end
|
133
133
|
|
134
134
|
context "#redirect" do
|
135
135
|
should "interpolate the argument string" do
|
136
|
-
@rack = Rack::Schmobile.new(@app, :redirect_to => "/wonderland/{{path}}")
|
137
|
-
assert_equal "/wonderland/wiffle", @rack.
|
136
|
+
@rack = Rack::Schmobile.new(@app, :redirect_to => "/wonderland", :redirect_with => "/{{path}}")
|
137
|
+
assert_equal "/wonderland/wiffle", @rack.redirect_location(request("PATH_INFO" => "wiffle"))
|
138
138
|
end
|
139
139
|
|
140
140
|
should "interpolate a multipart argument string" do
|
141
|
-
@rack = Rack::Schmobile.new(@app, :redirect_to => "/wonderland/{{path}}/lemurs/{{path}}")
|
142
|
-
assert_equal "/wonderland/wiffle/lemurs/wiffle", @rack.
|
141
|
+
@rack = Rack::Schmobile.new(@app, :redirect_to => "/wonderland/", :redirect_with => "{{path}}/lemurs/{{path}}")
|
142
|
+
assert_equal "/wonderland/wiffle/lemurs/wiffle", @rack.redirect_location(request("PATH_INFO" => "wiffle"))
|
143
143
|
end
|
144
144
|
end
|
145
145
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schmobile
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 8
|
10
|
+
version: 0.0.8
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Morten Primdahl
|