Skip to content

Commit

Permalink
Merge pull request #43 from bolshakov/feature/require-rails-explicitly
Browse files Browse the repository at this point in the history
Require rails explicitly
  • Loading branch information
adamcrown authored Mar 12, 2023
2 parents a9f1e17 + f96c1e9 commit a46158d
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 3 deletions.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,21 @@ Voight-Kampff relies on a [user agent](http://en.wikipedia.org/wiki/User_agent)

Installation
------------

`gem install voight_kampff`

If you're using Rails and want to add `ActionDispatch::Request#bot?` and `ActionDispatch::Request#human?` methods, require `voight_kampff/rails`:

```Gemfile
gem 'voight_kampff', require: 'voight_kampff/rails'
```

if you're using pure Rack, require it the following way:

```Gemfile
gem 'voight_kampff', require: 'voight_kampff/rack'
```

Configuration
-------------

Expand Down Expand Up @@ -49,6 +62,23 @@ In general the `#bot?` command tends to include all of these and I'm sure it's u

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.

Upgrading to version 2.0
------------------------

If you use Rails and `ActionDispatch::Request#bot?` and `ActionDispatch::Request#human?` methods, change your gemfile:

```diff
-gem 'voight_kampff'
+gem 'voight_kampff', require: 'voight_kampff/rails'
```

If you use Rack, change your gemfile:

```diff
-gem 'voight_kampff'
+gem 'voight_kampff', require: 'voight_kampff/rack'
```

FAQ
---
__Q:__ __What's with the name?__
Expand Down
2 changes: 0 additions & 2 deletions lib/voight_kampff.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

require 'voight_kampff/test'
require 'voight_kampff/methods'
require 'voight_kampff/rack_request' if defined?(Rack::Request)
require 'voight_kampff/engine' if defined?(Rails::Engine)

module VoightKampff
class << self
Expand Down
2 changes: 2 additions & 0 deletions lib/voight_kampff/rack.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require 'voight_kampff'
require 'voight_kampff/rack_request'
3 changes: 3 additions & 0 deletions lib/voight_kampff/rails.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require 'voight_kampff'
require 'voight_kampff/rack'
require 'voight_kampff/engine'
2 changes: 1 addition & 1 deletion lib/voight_kampff/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module VoightKampff
VERSION = '1.1.4'
VERSION = '2.0.0'
end
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'bundler/setup'
require 'combustion'
require 'voight_kampff'
require 'voight_kampff/rails'

Combustion.initialize! :action_controller

Expand Down

0 comments on commit a46158d

Please sign in to comment.