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 CHANGED
@@ -1 +1 @@
1
- 0.0.6
1
+ 0.0.8
@@ -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" => redirect(request) }, [] ]
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
- if @options[:if].is_a?(Proc)
68
- return false unless @options[:if].call(request)
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
- !redirect(request).empty? && request.path !~ /^#{redirect(request)}/
79
+ redirecting
80
+ end
81
+
82
+ def redirect_location(request)
83
+ "#{@options[:redirect_to]}#{redirect_with(request)}"
72
84
  end
73
85
 
74
- def redirect(request)
75
- destination = @options[:redirect_to].to_s
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
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{schmobile}
8
- s.version = "0.0.6"
8
+ s.version = "0.0.8"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Morten Primdahl"]
@@ -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.stubs(:redirect).returns("/hello")
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, :if => Proc.new { |request| false })
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.redirect(request("PATH_INFO" => "wiffle"))
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.redirect(request("PATH_INFO" => "wiffle"))
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: 19
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 6
10
- version: 0.0.6
9
+ - 8
10
+ version: 0.0.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - Morten Primdahl