Module: HotwireNativeVersionGate::Concern
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/hotwire_native_version_gate/concern.rb
Instance Method Summary collapse
-
#hotwire_native_html_attributes ⇒ Object
Space-separated data attributes for the root tag, for Tailwind custom variants.
- #native_android?(min_version = nil) ⇒ Boolean
-
#native_app_platform ⇒ Object
Platform ("iOS" or "Android") from the Hotwire Native User-Agent, when present.
-
#native_app_version ⇒ Object
Semantic version from the Hotwire Native User-Agent prefix, when present.
- #native_feature?(feature) ⇒ Boolean
- #native_ios?(min_version = nil) ⇒ Boolean
Instance Method Details
#hotwire_native_html_attributes ⇒ Object
Space-separated data attributes for the root tag, for Tailwind custom variants.
>Emits e.g. data-hotwire-native data-native-ios for iOS, or an empty string in the browser.
Uses hotwire_native_app? from turbo-rails when available; otherwise falls back to platform helpers.
64 65 66 67 68 69 70 71 |
# File 'lib/hotwire_native_version_gate/concern.rb', line 64 def hotwire_native_html_attributes attrs = [] hotwire_native = respond_to?(:hotwire_native_app?) ? hotwire_native_app? : (native_ios? || native_android?) attrs << "data-hotwire-native" if hotwire_native attrs << "data-native-ios" if native_ios? attrs << "data-native-android" if native_android? attrs.join(" ") end |
#native_android?(min_version = nil) ⇒ Boolean
37 38 39 40 |
# File 'lib/hotwire_native_version_gate/concern.rb', line 37 def native_android?(min_version = nil) user_agent = respond_to?(:request) && request.respond_to?(:user_agent) ? request.user_agent : nil VersionGate.android?(user_agent, min_version) end |
#native_app_platform ⇒ Object
Platform ("iOS" or "Android") from the Hotwire Native User-Agent, when present. Returns nil when the request is not from a native app.
53 54 55 56 |
# File 'lib/hotwire_native_version_gate/concern.rb', line 53 def native_app_platform user_agent = respond_to?(:request) && request.respond_to?(:user_agent) ? request.user_agent : nil VersionGate.app_platform(user_agent) end |
#native_app_version ⇒ Object
Semantic version from the Hotwire Native User-Agent prefix, when present. Returns nil when the request is not from a native app, or when no version is present.
44 45 46 47 48 49 |
# File 'lib/hotwire_native_version_gate/concern.rb', line 44 def native_app_version return unless native_ios? || native_android? user_agent = respond_to?(:request) && request.respond_to?(:user_agent) ? request.user_agent : nil VersionGate.app_version(user_agent) end |
#native_feature?(feature) ⇒ Boolean
27 28 29 30 |
# File 'lib/hotwire_native_version_gate/concern.rb', line 27 def native_feature?(feature) user_agent = respond_to?(:request) && request.respond_to?(:user_agent) ? request.user_agent : nil VersionGate.feature_enabled?(feature, user_agent, context: self) end |
#native_ios?(min_version = nil) ⇒ Boolean
32 33 34 35 |
# File 'lib/hotwire_native_version_gate/concern.rb', line 32 def native_ios?(min_version = nil) user_agent = respond_to?(:request) && request.respond_to?(:user_agent) ? request.user_agent : nil VersionGate.ios?(user_agent, min_version) end |