Skip to content

Commit 3cc4ae5

Browse files
committed
Document how to extend bots locally.
Close #536.
1 parent 808a87a commit 3cc4ae5

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,14 @@ Browser::Bot.matchers.delete(Browser::Bot::KeywordMatcher)
322322
Browser::Bot.matchers.delete(Browser::Bot::EmptyUserAgentMatcher)
323323
```
324324

325+
To extend the bot list, you can manipulate the methods below:
326+
327+
```ruby
328+
Browser::Bot.bots.merge!(new_bots_hash)
329+
Browser::Bot.bot_exceptions += new_exceptions
330+
Browser::Bot.search_engines.merge!(new_search_engines_hash)
331+
```
332+
325333
### Middleware
326334

327335
You can use the `Browser::Middleware` to redirect user agents.

search_engines.yml

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
---
12
ask jeeves: "Ask Jeeves"
23
baidu: "Chinese search engine"
34
bingbot: "Microsoft bing bot"

test/unit/bots_test.rb

+11
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,15 @@ class BotsTest < Minitest::Test
108108
assert_equal Browser::Bot::KeywordMatcher, browser.bot.why?
109109
end
110110
end
111+
112+
test "extends lists" do
113+
Browser::Bot.bots["another-bot"] = "Another bot"
114+
Browser::Bot.bot_exceptions.push("exclude-this-bot")
115+
Browser::Bot.search_engines["new-search-engine"] = "New search engine"
116+
117+
assert_equal "Another bot", Browser::Bot.bots["another-bot"]
118+
assert_includes Browser::Bot.bot_exceptions, "exclude-this-bot"
119+
assert_equal "New search engine",
120+
Browser::Bot.search_engines["new-search-engine"]
121+
end
111122
end

0 commit comments

Comments
 (0)