Merge pull request #1006 from airblade/warn_when_pt_cannot_load

Print warning when PT cannot be loaded ..
This commit is contained in:
Jared Beck 2017-10-25 12:33:45 -04:00 committed by GitHub
commit 9c037b510d
2 changed files with 16 additions and 3 deletions

View File

@ -16,7 +16,8 @@ recommendations of [keepachangelog.com](http://keepachangelog.com/).
### Fixed
- None
- [#1003](https://github.com/airblade/paper_trail/pull/1003) - Warn when PT
cannot be loaded because rails is not loaded yet.
## 8.0.0 (2017-10-04)

View File

@ -14,6 +14,12 @@ require "paper_trail/serializers/yaml"
# An ActiveRecord extension that tracks changes to your models, for auditing or
# versioning.
module PaperTrail
E_RAILS_NOT_LOADED = <<-EOS.squish.freeze
PaperTrail has been loaded too early, before rails is loaded. This can
happen when another gem defines the ::Rails namespace, then PT is loaded,
all before rails is loaded. You may want to reorder your Gemfile, or defer
the loading of PT by using `require: false` and a manual require elsewhere.
EOS
E_TIMESTAMP_FIELD_CONFIG = <<-EOS.squish.freeze
PaperTrail.timestamp_field= has been removed, without replacement. It is no
longer configurable. The timestamp field in the versions table must now be
@ -190,8 +196,14 @@ ActiveSupport.on_load(:active_record) do
end
# Require frameworks
if defined?(::Rails) && ActiveRecord::VERSION::STRING >= "3.2"
require "paper_trail/frameworks/rails"
if defined?(::Rails)
# Rails module is sometimes defined by gems like rails-html-sanitizer
# so we check for presence of Rails.application.
if defined?(::Rails.application)
require "paper_trail/frameworks/rails"
else
::Kernel.warn(::PaperTrail::E_RAILS_NOT_LOADED)
end
else
require "paper_trail/frameworks/active_record"
end