Skip to content

Commit

Permalink
Add Railtie config option: config.paper_trail.enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Hermanverschooten authored and jaredbeck committed Mar 6, 2016
1 parent 534aa77 commit 2029ea3
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -19,6 +19,7 @@

- [#689](https://github.com/airblade/paper_trail/pull/689) -
Rails 5 compatibility
- Added a rails config option: `config.paper_trail.enabled`

### Fixed

Expand All @@ -29,6 +30,8 @@
- [#635](https://github.com/airblade/paper_trail/issues/635) -
A bug where it was not possible to disable PT when using a multi-threaded
webserver.
- [#584](https://github.com/airblade/paper_trail/issues/584) -
Fixed deprecation warning for Active Record after_callback / after_commit

## 4.1.0 (2016-01-30)

Expand Down
7 changes: 7 additions & 0 deletions README.md
Expand Up @@ -418,6 +418,13 @@ PaperTrail.enabled = false

This is commonly used to speed up tests. See [Testing](#testing) below.

There is also a rails config option that does the same thing.

```ruby
# in config/environments/test.rb
config.paper_trail.enabled = false
```

### Per Request

Add a `paper_trail_enabled_for_controller` method to your controller.
Expand Down
4 changes: 0 additions & 4 deletions lib/paper_trail.rb
Expand Up @@ -170,10 +170,6 @@ def config
end
end

ActiveSupport.on_load(:active_record) do
include PaperTrail::Model
end

# Require frameworks
require "paper_trail/frameworks/sinatra"
if defined?(::Rails) && ActiveRecord::VERSION::STRING >= "3.2"
Expand Down
4 changes: 4 additions & 0 deletions lib/paper_trail/frameworks/active_record.rb
Expand Up @@ -2,3 +2,7 @@
# since otherwise the model(s) will get loaded in via the `Rails::Engine`.
require "paper_trail/frameworks/active_record/models/paper_trail/version_association"
require "paper_trail/frameworks/active_record/models/paper_trail/version"

ActiveSupport.on_load(:active_record) do
include PaperTrail::Model
end
5 changes: 5 additions & 0 deletions lib/paper_trail/frameworks/rails/engine.rb
Expand Up @@ -2,6 +2,11 @@ module PaperTrail
module Rails
class Engine < ::Rails::Engine
paths["app/models"] << "lib/paper_trail/frameworks/active_record/models"
config.paper_trail = ActiveSupport::OrderedOptions.new
initializer "paper_trail.initialisation" do |app|
ActiveRecord::Base.send :include, PaperTrail::Model
PaperTrail.enabled = app.config.paper_trail.fetch(:enabled, true)
end
end
end
end

0 comments on commit 2029ea3

Please sign in to comment.