schmobile 0.0.3 → 0.0.4
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 +14 -2
- data/schmobile.gemspec +1 -1
- data/test/test_schmobile.rb +5 -1
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
data/lib/rack/schmobile.rb
CHANGED
@@ -69,8 +69,20 @@ module Rack
|
|
69
69
|
def redirect(env)
|
70
70
|
destination = @options[:redirect_to].to_s
|
71
71
|
request = Rack::Request.new(env)
|
72
|
-
|
73
|
-
|
72
|
+
build_path(destination, request)
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
def build_path(destination, request)
|
78
|
+
final_destination = destination.dup
|
79
|
+
destination.scan(/\{\{\w+\}\}/) { |call|
|
80
|
+
func = call.scan(/\w+/).to_s
|
81
|
+
if request.respond_to?(func)
|
82
|
+
final_destination.sub!(/\{\{#{func}\}\}/, request.send(func))
|
83
|
+
end
|
84
|
+
}
|
85
|
+
final_destination
|
74
86
|
end
|
75
87
|
|
76
88
|
end
|
data/schmobile.gemspec
CHANGED
data/test/test_schmobile.rb
CHANGED
@@ -126,10 +126,14 @@ class TestSchmobile < Test::Unit::TestCase
|
|
126
126
|
end
|
127
127
|
|
128
128
|
context "#redirect" do
|
129
|
-
|
129
|
+
should "interpolate the argument string" do
|
130
130
|
@rack = Rack::Schmobile.new(@app, :redirect_to => "/wonderland/{{path}}")
|
131
131
|
assert_equal "/wonderland/wiffle", @rack.redirect(environment("PATH_INFO" => "wiffle"))
|
132
132
|
end
|
133
|
+
should "interpolate a multipart argument string" do
|
134
|
+
@rack = Rack::Schmobile.new(@app, :redirect_to => "/wonderland/{{path}}/lemurs/{{path}}")
|
135
|
+
assert_equal "/wonderland/wiffle/lemurs/wiffle", @rack.redirect(environment("PATH_INFO" => "wiffle"))
|
136
|
+
end
|
133
137
|
end
|
134
138
|
end
|
135
139
|
|
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: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Morten Primdahl
|