Skip to content

Commit

Permalink
Document how to extend bots locally.
Browse files Browse the repository at this point in the history
Close #536.
  • Loading branch information
fnando committed Apr 30, 2024
1 parent 808a87a commit 3cc4ae5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,14 @@ Browser::Bot.matchers.delete(Browser::Bot::KeywordMatcher)
Browser::Bot.matchers.delete(Browser::Bot::EmptyUserAgentMatcher)
```

To extend the bot list, you can manipulate the methods below:

```ruby
Browser::Bot.bots.merge!(new_bots_hash)
Browser::Bot.bot_exceptions += new_exceptions
Browser::Bot.search_engines.merge!(new_search_engines_hash)
```

### Middleware

You can use the `Browser::Middleware` to redirect user agents.
Expand Down
1 change: 1 addition & 0 deletions search_engines.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
ask jeeves: "Ask Jeeves"
baidu: "Chinese search engine"
bingbot: "Microsoft bing bot"
Expand Down
11 changes: 11 additions & 0 deletions test/unit/bots_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,15 @@ class BotsTest < Minitest::Test
assert_equal Browser::Bot::KeywordMatcher, browser.bot.why?
end
end

test "extends lists" do
Browser::Bot.bots["another-bot"] = "Another bot"
Browser::Bot.bot_exceptions.push("exclude-this-bot")
Browser::Bot.search_engines["new-search-engine"] = "New search engine"

assert_equal "Another bot", Browser::Bot.bots["another-bot"]
assert_includes Browser::Bot.bot_exceptions, "exclude-this-bot"
assert_equal "New search engine",
Browser::Bot.search_engines["new-search-engine"]
end
end

0 comments on commit 3cc4ae5

Please sign in to comment.