Skip to content

Commit f1ceb89

Browse files
committed
Version 2
Added ----- * Built-in cache with file-path and max-age * Automatically refresh from source (external repository) Removed ------- * Rake-tasks * A very large copy of external UA-bots list * `rack` as dependency Changed ------- * `voight_kampff/rack_request` isn't required by default * Default path for cache is now in `./tmp` directory instead of `./config` Development ----------- * [EditorConfig](https://editorconfig.org/) added * [RuboCop](https://github.com/rubocop-hq/rubocop) added and offenses fixed * Drop support for Ruby <= 2.2 (they even will not get security patches) * Ignore built gems for git
1 parent ece9e6b commit f1ceb89

27 files changed

Lines changed: 377 additions & 2436 deletions

.editorconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ Gemfile.lock
55
*.rbc
66
coverage
77
doc
8+
*.gem

.rubocop.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
AllCops:
2+
TargetRubyVersion: 2.3
3+
4+
Layout/MultilineMethodCallIndentation:
5+
EnforcedStyle: indented
6+
7+
Metrics/BlockLength:
8+
Exclude:
9+
- spec/**/*
10+
11+
Metrics/LineLength:
12+
Exclude:
13+
- spec/support/*

.ruby-version

Lines changed: 0 additions & 1 deletion
This file was deleted.

.travis.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
language: ruby
22
rvm:
3-
- 2.2.5
4-
- 2.3.1
3+
- 2.3
4+
- 2.4
5+
- 2.5
56
script: bundle exec rspec
67
before_install:
78
# fixes Travis CI error: NoMethodError: undefined method `spec' for nil:NilClass

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
source 'https://rubygems.org'
24

35
gemspec

README.md

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,38 @@ Installation
1313
Configuration
1414
-------------
1515

16-
A JSON file is used to match [user agent strings](http://simplyfast.info/browser) to a list of known bots.
16+
By default, this gem download [updatable list of known bots](https://github.com/monperrus/crawler-user-agents) and cache it into the `./tmp` directory.
1717

18-
If you'd like to use an [updated list](https://github.com/monperrus/crawler-user-agents) or make your own customizations, run `rake voight_kampff:import_user_agents`. This will download a `crawler-user-agents.json` file into the `./config` directory.
18+
You can disable file cache with `VoightKampff::Test.cache_path = nil`.
19+
20+
Default TTL of cache is 24 hours. You can change it with `VoightKampff::Test.max_age = number_of_seconds`.
1921

2022
__Note:__ The pattern entries in the JSON file are evaluated as [regular expressions](http://en.wikipedia.org/wiki/Regular_expression).
2123

2224
Usage
2325
-----
2426
There are three ways to use Voight-Kampff
2527

26-
1. Through Rack::Request such as in your [Ruby on Rails](http://rubyonrails.org) controllers:
27-
`request.bot?`
28+
1. Through `Rack::Request` in your app such as [Ruby on Rails](http://rubyonrails.org):
29+
```ruby
30+
require 'voight_kampff/rack_request'
31+
32+
request.bot?
33+
```
2834

29-
2. Through the `VoightKampff` module:
35+
2. Through the `VoightKampff` module:
3036
`VoightKampff.bot? 'your user agent string'`
3137

32-
3. Through a `VoightKampff::Test` instance:
38+
3. Through a `VoightKampff::Test` instance:
3339
`VoightKampff::Test.new('your user agent string').bot?`
3440

35-
All of the above examples accept `human?` and `bot?` methods. All of these methods will return `true` or `false`.
41+
All of the above examples accept `human?` and `bot?` methods.
42+
All of these methods will return `true` or `false`.
3643

3744
Upgrading to version 1.0
3845
------------------------
3946

40-
Version 1.0 uses a new source for a list of bot user agent strings since the old source was no longer maintained. This new source, unfortuately, does not include as much detail. Therefore the following methods have been deprecated:
47+
Version 1.0 uses a new source for a list of bot user agent strings since the old source was no longer maintained. This new source, unfortunately, does not include as much detail. Therefore the following methods have been deprecated:
4148
- `#browser?`
4249
- `#checker?`
4350
- `#downloader?`
@@ -49,14 +56,21 @@ In general the `#bot?` command tends to include all of these and I'm sure it's u
4956

5057
Also, the gem no longer extends `ActionDispatch::Request` instead it extends `Rack::Request` which `ActionDispatch::Request` inherits from. This allows the same functionality for Rails while opening the gem up to other rack-based projects.
5158

59+
Upgrading to version 2.0
60+
------------------------
61+
62+
Version 2.0 uses a built-in cache instead of `rake` tasks.
63+
64+
Also, you have to explicitly require `voight_kampff/rack_request` for `Rack::Request` patching.
65+
5266
FAQ
5367
---
54-
__Q:__ __What's with the name?__
68+
__Q:__ __What's with the name?__
5569
__A:__ It's the [machine in Blade Runner](http://en.wikipedia.org/wiki/Blade_Runner#Voight-Kampff_machine) that is used to test whether someone is a human or a replicant.
5670

57-
__Q:__ __I've found a bot that isn't being matched__
71+
__Q:__ __I've found a bot that isn't being matched__
5872
__A:__ The list is being pulled from [github.com/monperrus/crawler-user-agents](https://github.com/monperrus/crawler-user-agents).
59-
If you'd like to have entries added to the list, please create a pull request with that project. Once that pull request is merged, feel free to create an issue here and I'll release a new gem version with the updated list. In the meantime you can always run `rake voight_kampff:import_user_agents` on your project to get that updated list.
73+
If you'd like to have entries added to the list, please create a pull request with that project. Once that pull request is merged, you'll be get the new version at the next cache update. In the meantime you can always manually flush the cache in your project to get that updated list.
6074

6175
__Q:__ __Why don't you use the user agent list from ______________
6276
If you know of a better source for a list of bot user agent strings, please create an issue and let me know. I'm open to switching to a better source or supporting multiple sources. There are others out there but I like the openness of monperrus' list.
@@ -67,7 +81,7 @@ Thanks to [github.com/monperrus/crawler-user-agents](https://github.com/monperru
6781

6882
Contributing
6983
------------
70-
PR without tests will not get merged, Make sure you write tests for api and rails app.
84+
PR without tests will not get merged, Make sure you write tests for API and Rails app.
7185
Feel free to ask for help, if you do not know how to write a determined test.
7286

7387
Running Tests?

config.ru

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'rubygems'
24
require 'bundler'
35

0 commit comments

Comments
 (0)