Class: HotwireNativeVersionGate::VersionGate
- Inherits:
-
Object
- Object
- HotwireNativeVersionGate::VersionGate
- Defined in:
- lib/hotwire_native_version_gate/version_gate.rb
Constant Summary collapse
- DEFAULT_NATIVE_VERSION_REGEX =
Default regex example: Hotwire Native App iOS/1.0.0; Expected capture groups: platform = (iOS|Android), version = semantic version
/\bHotwire Native App (?<platform>iOS|Android)\/(?<version>\d+(?:\.\d+)*)\b/- FALLBACK_NATIVE_VERSION_REGEX =
Default fallback for apps that don’t have the version in the User Agent ex: Hotwire Native iOS;
/\b(Turbo|Hotwire) Native (?<platform>iOS|Android)\b/
Class Attribute Summary collapse
-
.native_features ⇒ Object
readonly
Returns the value of attribute native_features.
-
.native_version_regexes ⇒ Object
Returns the value of attribute native_version_regexes.
Class Method Summary collapse
- .android?(user_agent, min_version = nil) ⇒ Boolean
- .feature_enabled?(feature, user_agent, context: nil) ⇒ Boolean
- .ios?(user_agent, min_version = nil) ⇒ Boolean
- .native_feature(feature, ios: false, android: false) ⇒ Object
Class Attribute Details
.native_features ⇒ Object (readonly)
Returns the value of attribute native_features.
15 16 17 |
# File 'lib/hotwire_native_version_gate/version_gate.rb', line 15 def native_features @native_features end |
.native_version_regexes ⇒ Object
Returns the value of attribute native_version_regexes.
15 16 17 |
# File 'lib/hotwire_native_version_gate/version_gate.rb', line 15 def native_version_regexes @native_version_regexes end |
Class Method Details
.android?(user_agent, min_version = nil) ⇒ Boolean
43 44 45 |
# File 'lib/hotwire_native_version_gate/version_gate.rb', line 43 def android?(user_agent, min_version = nil) platform_check?('android', user_agent, min_version) end |
.feature_enabled?(feature, user_agent, context: nil) ⇒ Boolean
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/hotwire_native_version_gate/version_gate.rb', line 27 def feature_enabled?(feature, user_agent, context: nil) @native_features ||= {} return false unless @native_features.key?(feature) platform = match_platform(user_agent) return false if platform.nil? platform_key = platform.downcase.to_sym feature_config = @native_features[feature][platform_key] handle_feature(feature_config, user_agent, context: context) end |
.ios?(user_agent, min_version = nil) ⇒ Boolean
39 40 41 |
# File 'lib/hotwire_native_version_gate/version_gate.rb', line 39 def ios?(user_agent, min_version = nil) platform_check?('ios', user_agent, min_version) end |
.native_feature(feature, ios: false, android: false) ⇒ Object
22 23 24 25 |
# File 'lib/hotwire_native_version_gate/version_gate.rb', line 22 def native_feature(feature, ios: false, android: false) @native_features ||= {} @native_features[feature] = { ios: ios, android: android } end |