Skip to content

Commit

Permalink
Autoload models via the PaperTrail::Rails::Engine if the gem is being…
Browse files Browse the repository at this point in the history
… used within Rails
  • Loading branch information
batter committed Jun 5, 2014
1 parent 87751ac commit ee338a5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
20 changes: 12 additions & 8 deletions lib/paper_trail.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
require 'paper_trail/config'
require 'paper_trail/has_paper_trail'
require 'paper_trail/cleaner'
require 'paper_trail/version_number'
# Require core library
Dir[File.join(File.dirname(__FILE__), 'paper_trail', '*.rb')].each do |file|
require File.join('paper_trail', File.basename(file, '.rb'))
end

# Require serializers
Dir[File.join(File.dirname(__FILE__), 'paper_trail', 'serializers', '*.rb')].each { |file| require file }
Dir[File.join(File.dirname(__FILE__), 'paper_trail', 'serializers', '*.rb')].each do |file|
require File.join('paper_trail', 'serializers', File.basename(file, '.rb'))
end

module PaperTrail
extend PaperTrail::Cleaner
Expand Down Expand Up @@ -118,14 +120,16 @@ def self.configure
rescue LoadError; end # will rescue if `ProtectedAttributes` gem is not available
end

require 'paper_trail/version'

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

# Require frameworks
require 'paper_trail/frameworks/sinatra'
require 'paper_trail/frameworks/rails' if defined? Rails
if defined? Rails
require 'paper_trail/frameworks/rails'
else
require 'paper_trail/frameworks/active_record'
end
require 'paper_trail/frameworks/rspec' if defined? RSpec
require 'paper_trail/frameworks/cucumber' if defined? World
5 changes: 5 additions & 0 deletions lib/paper_trail/frameworks/active_record.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# This file only needs to be loaded if the gem is being used outside of Rails, since otherwise
# the model(s) will get loaded in via the `Rails::Engine`
Dir[File.join(File.dirname(__FILE__), 'active_record', 'models', 'paper_trail', '*.rb')].each do |file|
require "paper_trail/frameworks/active_record/models/paper_trail/#{File.basename(file, '.rb')}"
end
File renamed without changes.
1 change: 1 addition & 0 deletions lib/paper_trail/frameworks/rails/engine.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module PaperTrail
module Rails
class Engine < ::Rails::Engine
paths['app/models'] << 'lib/paper_trail/frameworks/active_record/models'
end
end
end

0 comments on commit ee338a5

Please sign in to comment.