Module: BotVerification::ControllerConcern
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/bot_verification/controller_concern.rb
Overview
Controller concern for bot verification with session-based caching
Instance Method Summary collapse
-
#ai_bot_user_agent? ⇒ Boolean
Check if user agent looks like an AI bot.
-
#bot_user_agent? ⇒ Boolean
Check if user agent looks like a bot (regardless of verification).
-
#detected_bot_type ⇒ Symbol?
Get the detected bot type for the current request (if any).
-
#search_bot_user_agent? ⇒ Boolean
Check if user agent looks like a search engine bot.
-
#verified_ai_bot?(strict: true) ⇒ Boolean
Check specifically if request is from a verified AI bot.
-
#verified_good_bot?(mode: :search_engines) ⇒ Boolean
Check if current request is from a verified good bot Uses session caching to avoid repeated verification calls.
Instance Method Details
#ai_bot_user_agent? ⇒ Boolean
Check if user agent looks like an AI bot
75 76 77 |
# File 'lib/bot_verification/controller_concern.rb', line 75 def ai_bot_user_agent? Service.ai_bot_user_agent?(request.user_agent) end |
#bot_user_agent? ⇒ Boolean
Check if user agent looks like a bot (regardless of verification)
68 69 70 |
# File 'lib/bot_verification/controller_concern.rb', line 68 def bot_user_agent? detected_bot_type.present? end |
#detected_bot_type ⇒ Symbol?
Get the detected bot type for the current request (if any)
61 62 63 |
# File 'lib/bot_verification/controller_concern.rb', line 61 def detected_bot_type @_detected_bot_type ||= Service.detect_bot_type(request.user_agent) end |
#search_bot_user_agent? ⇒ Boolean
Check if user agent looks like a search engine bot
82 83 84 |
# File 'lib/bot_verification/controller_concern.rb', line 82 def search_bot_user_agent? Service.search_bot_user_agent?(request.user_agent) end |
#verified_ai_bot?(strict: true) ⇒ Boolean
Check specifically if request is from a verified AI bot
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/bot_verification/controller_concern.rb', line 38 def verified_ai_bot?(strict: true) cache_key = bot_session_cache_key return false unless cache_key cached = read_bot_session_cache(cache_key) return true if cached && cached[:ai_verified] == true result = Service.verified_ai_bot?( request.remote_ip, request.user_agent, strict: strict ) if result write_bot_session_cache(cache_key, ai_verified: true, bot_type: detected_bot_type) end result end |
#verified_good_bot?(mode: :search_engines) ⇒ Boolean
Check if current request is from a verified good bot Uses session caching to avoid repeated verification calls
27 28 29 30 31 32 |
# File 'lib/bot_verification/controller_concern.rb', line 27 def verified_good_bot?(mode: :search_engines) return @_verified_good_bot if defined?(@_verified_good_bot) && @_verification_mode == mode @_verification_mode = mode @_verified_good_bot = check_bot_with_session_cache(mode: mode) end |