Module: RubyNative::NativeDetection
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/ruby_native/native_detection.rb
Instance Method Summary collapse
- #native_app? ⇒ Boolean
-
#native_platform ⇒ Object
Returns “ios” or “android” for native requests, nil for web browsers.
- #native_version ⇒ Object
Instance Method Details
#native_app? ⇒ Boolean
9 10 11 |
# File 'lib/ruby_native/native_detection.rb', line 9 def native_app? request.user_agent.to_s.include?("Ruby Native") end |
#native_platform ⇒ Object
Returns “ios” or “android” for native requests, nil for web browsers. Used by view helpers to pick the right icon from ‘icons: { ios:, android: }`.
20 21 22 23 24 25 |
# File 'lib/ruby_native/native_detection.rb', line 20 def native_platform ua = request.user_agent.to_s return "ios" if ua.include?("Ruby Native iOS") return "android" if ua.include?("Ruby Native Android") nil end |
#native_version ⇒ Object
13 14 15 16 |
# File 'lib/ruby_native/native_detection.rb', line 13 def native_version match = request.user_agent.to_s.match(/RubyNative\/([\d.]+)/) NativeVersion.new(match ? match[1] : "0") end |