Created
May 14, 2021 13:47
-
-
Save somenugget/706909245a3de4276396263e4e70b3b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Concerns | |
module BrowserCheck | |
extend ActiveSupport::Concern | |
NOT_SUPPORTED_VERSIONS = { | |
ie: 11, | |
edge: 19, | |
ios: 12, | |
android: 6 | |
}.freeze | |
included do | |
before_action :check_browser | |
end | |
private | |
def check_browser | |
byebug | |
if browser_not_supported? | |
redirect_to update_browser_path | |
elsif os_not_supported? | |
redirect_to update_os_path | |
end | |
end | |
def browser_not_supported? | |
[ | |
browser.ie?(not_supported_versions_for(:ie)), | |
browser.edge?(not_supported_versions_for(:edge)) | |
].any? | |
end | |
def os_not_supported? | |
[ | |
browser.platform.ios?(not_supported_versions_for(:ios)), | |
browser.platform.android?(not_supported_versions_for(:android)) | |
].any? | |
end | |
def not_supported_versions_for(key) | |
next_version = NOT_SUPPORTED_VERSIONS[key] + 1 | |
"< #{next_version}" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment