diff --git a/README.md b/README.md index 5721595b..e9505134 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/search_engines.yml b/search_engines.yml index 98669e2f..8dd648f7 100644 --- a/search_engines.yml +++ b/search_engines.yml @@ -1,3 +1,4 @@ +--- ask jeeves: "Ask Jeeves" baidu: "Chinese search engine" bingbot: "Microsoft bing bot" diff --git a/test/unit/bots_test.rb b/test/unit/bots_test.rb index b4985e7c..53919806 100644 --- a/test/unit/bots_test.rb +++ b/test/unit/bots_test.rb @@ -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