schmobile 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/rack/schmobile/user_agents.rb +17 -1
- data/schmobile.gemspec +2 -2
- data/test/test_rack_request.rb +4 -0
- metadata +5 -5
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
@@ -9,6 +9,10 @@ module Rack
|
|
9
9
|
sprint symbian telit ucweb up.b upg1 vodafone webos windows\ ce x240 x320 xiino
|
10
10
|
)
|
11
11
|
|
12
|
+
NON_MOBILE_USER_AGENTS = %w(
|
13
|
+
ipad
|
14
|
+
)
|
15
|
+
|
12
16
|
def self.remove_user_agent_pattern(pattern)
|
13
17
|
MOBILE_USER_AGENTS.delete(pattern)
|
14
18
|
@mobile_agent_matcher = nil
|
@@ -20,13 +24,25 @@ module Rack
|
|
20
24
|
end
|
21
25
|
|
22
26
|
def self.is_mobile_agent?(user_agent)
|
23
|
-
|
27
|
+
agent = user_agent.to_s.downcase
|
28
|
+
agent !~ non_mobile_agent_matcher && !(agent =~ mobile_agent_matcher).nil?
|
24
29
|
end
|
25
30
|
|
26
31
|
def self.mobile_agent_matcher
|
27
32
|
@mobile_agent_matcher ||= Regexp.new(MOBILE_USER_AGENTS.uniq.compact.map { |v| Regexp.escape(v) }.join("|"))
|
28
33
|
end
|
29
34
|
|
35
|
+
def self.non_mobile_agent_matcher
|
36
|
+
@non_mobile_agent_matcher ||= Regexp.new(NON_MOBILE_USER_AGENTS.uniq.compact.map { |v| Regexp.escape(v) }.join("|"))
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.matched_by?(user_agent)
|
40
|
+
MOBILE_USER_AGENTS.each do |agent|
|
41
|
+
return agent if user_agent =~ /#{agent}/
|
42
|
+
end
|
43
|
+
nil
|
44
|
+
end
|
45
|
+
|
30
46
|
end
|
31
47
|
end
|
32
48
|
end
|
data/schmobile.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{schmobile}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.4.0"
|
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"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-06-30}
|
13
13
|
s.description = %q{Used to determine if a request is from a mobile client, and possibly redirect it if that's the case}
|
14
14
|
s.email = %q{morten@zendesk.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/test/test_rack_request.rb
CHANGED
@@ -51,6 +51,10 @@ class TestRackRequest < Test::Unit::TestCase
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
+
should "not detect an ipad as a mobile browser" do
|
55
|
+
assert !request("HTTP_USER_AGENT" => ipad).is_mobile?
|
56
|
+
end
|
57
|
+
|
54
58
|
should "return false when forced in the session" do
|
55
59
|
Rack::Request.any_instance.stubs(:session).returns({ Rack::Schmobile::IS_MOBILE => false })
|
56
60
|
assert !request("HTTP_USER_AGENT" => iphone).is_mobile?
|
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:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 4
|
9
|
+
- 0
|
10
|
+
version: 0.4.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Morten Primdahl
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-06-30 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|