hotwire_native_version_gate 1.0.0 → 1.1.0
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.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/hotwire_native_version_gate/concern.rb +17 -1
- data/lib/hotwire_native_version_gate/version_gate.rb +16 -6
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 82aeb1d4b3df07819f0139ef15823d609d7c0b9aecd997ab6c66ce688af5a4eb
|
|
4
|
+
data.tar.gz: ad201566715e4092834b9b6dab4fb3938df20768e5de42d8c216a6957e397920
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0c3de617885b7dd0db677dfa453ede08723af66876d787546c939fb93172df86d45f09c0cf7ab167d9661b367b11f51e13fa76b9c6662930b8a61938897c52f2
|
|
7
|
+
data.tar.gz: 9f44ebb33a9eecd21ab310944a238eb7030422a4ad854ed43dc97128e44572fa437050eda9eb62b72a273aebecf2f29c1d21649ac8284df967b2e541f0851e2d
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
1.
|
|
1
|
+
1.1.0
|
|
@@ -20,7 +20,7 @@ module HotwireNativeVersionGate
|
|
|
20
20
|
|
|
21
21
|
included do
|
|
22
22
|
if respond_to?(:helper_method)
|
|
23
|
-
helper_method :native_feature?, :native_ios?, :native_android
|
|
23
|
+
helper_method :native_feature?, :native_ios?, :native_android?, :native_app_version, :native_app_platform
|
|
24
24
|
end
|
|
25
25
|
end
|
|
26
26
|
|
|
@@ -38,5 +38,21 @@ module HotwireNativeVersionGate
|
|
|
38
38
|
user_agent = respond_to?(:request) && request.respond_to?(:user_agent) ? request.user_agent : nil
|
|
39
39
|
VersionGate.android?(user_agent, min_version)
|
|
40
40
|
end
|
|
41
|
+
|
|
42
|
+
# Semantic version from the Hotwire Native User-Agent prefix, when present.
|
|
43
|
+
# Returns nil when the request is not from a native app, or when no version is present.
|
|
44
|
+
def native_app_version
|
|
45
|
+
return unless native_ios? || native_android?
|
|
46
|
+
|
|
47
|
+
user_agent = respond_to?(:request) && request.respond_to?(:user_agent) ? request.user_agent : nil
|
|
48
|
+
VersionGate.app_version(user_agent)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Platform ("iOS" or "Android") from the Hotwire Native User-Agent, when present.
|
|
52
|
+
# Returns nil when the request is not from a native app.
|
|
53
|
+
def native_app_platform
|
|
54
|
+
user_agent = respond_to?(:request) && request.respond_to?(:user_agent) ? request.user_agent : nil
|
|
55
|
+
VersionGate.app_platform(user_agent)
|
|
56
|
+
end
|
|
41
57
|
end
|
|
42
58
|
end
|
|
@@ -28,7 +28,7 @@ module HotwireNativeVersionGate
|
|
|
28
28
|
@native_features ||= {}
|
|
29
29
|
return false unless @native_features.key?(feature)
|
|
30
30
|
|
|
31
|
-
platform =
|
|
31
|
+
platform = app_platform(user_agent)
|
|
32
32
|
return false if platform.nil?
|
|
33
33
|
|
|
34
34
|
platform_key = platform.downcase.to_sym
|
|
@@ -44,6 +44,20 @@ module HotwireNativeVersionGate
|
|
|
44
44
|
platform_check?('android', user_agent, min_version)
|
|
45
45
|
end
|
|
46
46
|
|
|
47
|
+
# Platform ("iOS" or "Android") from the Hotwire Native User-Agent, when present.
|
|
48
|
+
# Returns nil when the request is not from a native app.
|
|
49
|
+
def app_platform(user_agent)
|
|
50
|
+
match_key(user_agent, :platform)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Semantic version from the Hotwire Native User-Agent prefix, when present.
|
|
54
|
+
# Returns nil when the request is not from a native app, or when no version is present.
|
|
55
|
+
def app_version(user_agent)
|
|
56
|
+
return unless app_platform(user_agent)
|
|
57
|
+
|
|
58
|
+
match_key(user_agent, :version)
|
|
59
|
+
end
|
|
60
|
+
|
|
47
61
|
private
|
|
48
62
|
|
|
49
63
|
def validate_regexes(regexes)
|
|
@@ -68,15 +82,11 @@ module HotwireNativeVersionGate
|
|
|
68
82
|
end
|
|
69
83
|
|
|
70
84
|
def platform_check?(platform, user_agent, min_version = nil)
|
|
71
|
-
return false unless
|
|
85
|
+
return false unless app_platform(user_agent)&.downcase == platform
|
|
72
86
|
return true unless min_version
|
|
73
87
|
compare_version(user_agent, min_version)
|
|
74
88
|
end
|
|
75
89
|
|
|
76
|
-
def match_platform(user_agent)
|
|
77
|
-
match_key(user_agent, :platform)
|
|
78
|
-
end
|
|
79
|
-
|
|
80
90
|
def compare_version(user_agent, min_version)
|
|
81
91
|
version = match_key(user_agent, :version)
|
|
82
92
|
return false unless version
|