paper_trail-active_record 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/.yardopts +7 -0
- data/Changelog.md +3 -0
- data/Gemfile +6 -0
- data/License +18 -0
- data/Rakefile +6 -0
- data/Readme.md +95 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/paper_trail/active_record.rb +23 -0
- data/lib/paper_trail/active_record/base_extensions.rb +128 -0
- data/lib/paper_trail/active_record/configuration.rb +15 -0
- data/lib/paper_trail/active_record/or_deleted.rb +88 -0
- data/lib/paper_trail/active_record/version.rb +7 -0
- data/lib/paper_trail/active_record/version_extensions.rb +76 -0
- data/paper_trail-active_record.gemspec +39 -0
- metadata +189 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7fa97181a35e9ee580bb03d4bdef4da4d9a05aa6d90561274df1d8a69c08445c
|
4
|
+
data.tar.gz: 6888e2d9591bf6764bb66abba3dfd85b4e82d7a7a3628f2b6862473aa9b356f8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 953db9408ab0369e96e693ec79546eacd299b0009635546740222358525bf21d42f1c91f6c2b7024e183d3e11e53b73630eabd0d7ac34ca919585596cf7ef3a0
|
7
|
+
data.tar.gz: e9e680685bcb3c5de6f575c515f53432639338d59514cc259b3f4c579a02a428d5d7a8a19989c97b3537ba5bad673020cb704c5b8e3430ba197148316f1fb815
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/.yardopts
ADDED
data/Changelog.md
ADDED
data/Gemfile
ADDED
data/License
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Copyright (c) 2020 Tyler Rick, K3 Integrations
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
4
|
+
associated documentation files (the "Software"), to deal in the Software without restriction,
|
5
|
+
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
6
|
+
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
7
|
+
furnished to do so, subject to the following conditions:
|
8
|
+
|
9
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial
|
10
|
+
portions of the Software.
|
11
|
+
|
12
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
13
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
14
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
15
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
16
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
17
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
18
|
+
SOFTWARE.
|
data/Rakefile
ADDED
data/Readme.md
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
# PaperTrail::ActiveRecord
|
2
|
+
|
3
|
+
[![Gem Version][1]][2]
|
4
|
+
[![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](https://rdoc.info/github/TylerRick/paper_trail-active_record/master)
|
5
|
+
|
6
|
+
An extension to [PaperTrail](https://github.com/paper-trail-gem/paper_trail)
|
7
|
+
that adds some useful extensions to models that have `has_paper_trail` and to the Version model.
|
8
|
+
|
9
|
+
## Methods added to models with `has_paper_trail`
|
10
|
+
|
11
|
+
- `.versions`
|
12
|
+
- `.find_deleted_version`
|
13
|
+
- `.find_deleted`
|
14
|
+
- `.has_many_versions`
|
15
|
+
- `.has_related_versions`
|
16
|
+
- `.has_versions_with_all_related`
|
17
|
+
- `created_version`
|
18
|
+
- `paper_trail_update_column_using_value_from_changes`
|
19
|
+
- `paper_trail_update_columns_using_value_from_changes`
|
20
|
+
|
21
|
+
## Methods added to `PaperTrail::Version` (`VersionConcern`)
|
22
|
+
|
23
|
+
- `.preceding_inclusive`
|
24
|
+
- `.between_inclusive`
|
25
|
+
- `scope :where_object_changed`
|
26
|
+
- `scope :where_object_changed_any`
|
27
|
+
- `#action`
|
28
|
+
- `#item_class`
|
29
|
+
|
30
|
+
## `OrDeleted`
|
31
|
+
|
32
|
+
If you include this module into a model, it will automatically add a `{association}_or_deleted`
|
33
|
+
method for every `belongs_to` or `has_one` association that is defined.
|
34
|
+
|
35
|
+
Because it reflects on all associations on that model as soon as it is included, make sure to
|
36
|
+
include it *after* all of your associations are defined.
|
37
|
+
|
38
|
+
If you want more control, and don't want it to add anything automatically, you can manually call
|
39
|
+
`define_assoc_or_deleted :association` for each association that you want to have a
|
40
|
+
`{association}_or_deleted` method.
|
41
|
+
|
42
|
+
If you want it to automatically be added for all assocations on *all* application models, you can
|
43
|
+
use [gem 'active_record_include'](https://github.com/TylerRick/active_record_include) like this:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
class ApplicationRecord < ActiveRecord::Base
|
47
|
+
include_when_connected PaperTrail::ActiveRecord::OrDeleted
|
48
|
+
```
|
49
|
+
|
50
|
+
### `def define_assoc_or_deleted(assoc_name, suffix: nil)`
|
51
|
+
|
52
|
+
Defines a `{association}_or_deleted` method for the given association. This method will call
|
53
|
+
the usual association method to try to find the associated record but if that returns nil,
|
54
|
+
will fall back to looking for a deleted record from the `versions` history (using
|
55
|
+
`klass.find_deleted`).
|
56
|
+
|
57
|
+
You can replace the `or_deleted` part with a different suffix using `suffix:` option.
|
58
|
+
|
59
|
+
You can even give it the same name as the existing association method if you want to override
|
60
|
+
the existing method with one that always falls back to looking for a deleted record.
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
class Post
|
64
|
+
belongs_to :author
|
65
|
+
# overrides author method with a version that finds deleted if not found
|
66
|
+
define_assoc_or_deleted :author, suffix: nil
|
67
|
+
```
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
## Installation
|
72
|
+
|
73
|
+
Add this line to your application's Gemfile:
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
gem 'paper_trail-active_record'
|
77
|
+
```
|
78
|
+
|
79
|
+
And then execute:
|
80
|
+
|
81
|
+
$ bundle
|
82
|
+
|
83
|
+
## Development
|
84
|
+
|
85
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
86
|
+
|
87
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
88
|
+
|
89
|
+
## Contributing
|
90
|
+
|
91
|
+
Bug reports and pull requests are welcome on GitHub at
|
92
|
+
https://github.com/TylerRick/paper_trail-active_record.
|
93
|
+
|
94
|
+
[1]: https://badge.fury.io/rb/paper_trail-active_record.svg
|
95
|
+
[2]: https://rubygems.org/gems/paper_trail-active_record
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "paper_trail/rails"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'paper_trail'
|
2
|
+
|
3
|
+
require_relative 'active_record/version'
|
4
|
+
|
5
|
+
require_relative 'active_record/configuration'
|
6
|
+
require_relative 'active_record/base_extensions'
|
7
|
+
require_relative 'active_record/or_deleted'
|
8
|
+
require_relative 'active_record/version_extensions'
|
9
|
+
|
10
|
+
module PaperTrail
|
11
|
+
module ActiveRecord
|
12
|
+
class << self
|
13
|
+
def configuration
|
14
|
+
@configuration ||= Configuration.new
|
15
|
+
end
|
16
|
+
alias_method :config, :configuration
|
17
|
+
|
18
|
+
def configure
|
19
|
+
yield config
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
module PaperTrail::ActiveRecord
|
2
|
+
|
3
|
+
# Extensions to ActiveRecord::Base to better support PaperTrail
|
4
|
+
module BaseExtensions
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
# Versions for STI subclasses are included by default. Pass subclasses: false to *only* include
|
9
|
+
# versions for the base class (no subclasses).
|
10
|
+
def versions(subclasses: true)
|
11
|
+
if self == base_class and subclasses
|
12
|
+
Version.where(item_type: base_class.name)
|
13
|
+
else
|
14
|
+
Version.where(item_type: base_class.name, item_subtype: self.name)
|
15
|
+
end.tap do |versions|
|
16
|
+
PaperTrail::ActiveRecord.config.versions_extends.each do |mod|
|
17
|
+
versions.extend(mod)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def find_deleted_version(id)
|
23
|
+
Version.destroys.with_item_keys(base_class.name, id).first
|
24
|
+
end
|
25
|
+
|
26
|
+
def find_deleted_version!(id)
|
27
|
+
Version.destroys.with_item_keys(base_class.name, id).first!
|
28
|
+
end
|
29
|
+
|
30
|
+
# Unlike find, does not raise RecordNotFound if not found
|
31
|
+
def find_deleted(id)
|
32
|
+
find_deleted_version(id)&.reify
|
33
|
+
end
|
34
|
+
|
35
|
+
def find_deleted!(id)
|
36
|
+
find_deleted_version!(id).reify
|
37
|
+
end
|
38
|
+
|
39
|
+
def valid_versions_association_names
|
40
|
+
[
|
41
|
+
:versions,
|
42
|
+
:versions_with_related,
|
43
|
+
:versions_with_all_related,
|
44
|
+
|
45
|
+
:related_versions,
|
46
|
+
:all_related_versions,
|
47
|
+
]
|
48
|
+
end
|
49
|
+
def versions_association_names
|
50
|
+
reflect_on_all_associations.map(&:name).grep(/versions/)
|
51
|
+
end
|
52
|
+
|
53
|
+
def has_many_versions(name, *args, **options)
|
54
|
+
has_many name, *args, class_name: 'Version', extend: [PaperTrail::ActiveRecord.config.versions_extends], **options
|
55
|
+
end
|
56
|
+
|
57
|
+
# Creates associations for finding related versions — that is, versions for related/children
|
58
|
+
# records of this record, not just versions of this record itself.
|
59
|
+
#
|
60
|
+
# The way it finds those related associations is by querying the versions table on a "metadata"
|
61
|
+
# column, for example user_id, instead of on item_id (which is what you use to get versions
|
62
|
+
# directly for a particular record).
|
63
|
+
#
|
64
|
+
# foreign_key identifies which metadata column links versions for related/child records back
|
65
|
+
# to the "parent" record.
|
66
|
+
#
|
67
|
+
# For example, to create a :versions_with_related association on User that finds all versions
|
68
|
+
# that have changed a particular user record or any of its related/child records, configure
|
69
|
+
# paper_trail for all related/child models with meta: :user_id, and then pass :user_id as the
|
70
|
+
# foreign_key to has_related_versions.
|
71
|
+
#
|
72
|
+
def has_related_versions(foreign_key, item_types: nil)
|
73
|
+
parent_model_name = name
|
74
|
+
with_options(foreign_key: foreign_key) do |_|
|
75
|
+
if item_types
|
76
|
+
# self + filtered related records
|
77
|
+
_.has_many_versions :versions_with_related, -> { where(arel_table[:item_type].in([parent_model_name] + item_types)) }
|
78
|
+
# filtered related records only (exclude self)
|
79
|
+
_.has_many_versions :related_versions, -> { where(arel_table[:item_type].in( item_types)) }
|
80
|
+
has_versions_with_all_related foreign_key, 'all_'
|
81
|
+
else
|
82
|
+
# Not filtered by item_types, so just make the "all" association be the default instead of
|
83
|
+
# defining 2 associations that are identical.
|
84
|
+
has_versions_with_all_related foreign_key, ''
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def has_versions_with_all_related(foreign_key, all_prefix)
|
90
|
+
parent_model_name = name
|
91
|
+
with_options(foreign_key: foreign_key) do |_|
|
92
|
+
# self + all related records (any item_type)
|
93
|
+
_.has_many_versions :"versions_with_#{all_prefix}related"
|
94
|
+
# all related records *only* (exclude self)
|
95
|
+
_.has_many_versions :"#{all_prefix}related_versions", -> { where(arel_table[:item_type].not_eq(parent_model_name)) }
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end # module ClassMethods
|
99
|
+
|
100
|
+
def created_version
|
101
|
+
versions.creates.first
|
102
|
+
end
|
103
|
+
|
104
|
+
# Workaround to prevent paper_trail from incorrectly recording a change from new value to new value.
|
105
|
+
# Useful if you've already set the attribute to the new value and now you want to save that change
|
106
|
+
# to the database, with versioning.
|
107
|
+
def paper_trail_update_column_using_value_from_changes(name, changes: changes(), touch: true)
|
108
|
+
paper_trail_update_columns_using_value_from_changes name, changes: changes, touch: touch
|
109
|
+
end
|
110
|
+
|
111
|
+
# Tested by: spec/lib/active_record/base_extensions/paper_trail_extensions_spec.rb
|
112
|
+
def paper_trail_update_columns_using_value_from_changes(*names, changes: changes(), touch: true)
|
113
|
+
new_values = {}
|
114
|
+
names.each do |name|
|
115
|
+
(old_value, new_value = changes[name]) or next
|
116
|
+
self.send("#{name}=", old_value)
|
117
|
+
new_values[name] = new_value
|
118
|
+
end
|
119
|
+
new_values[:updated_at] = Time.now if has_attribute?(:updated_at) && touch
|
120
|
+
paper_trail.update_columns new_values
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
ActiveRecord::Base.class_eval do
|
126
|
+
include PaperTrail::ActiveRecord::BaseExtensions
|
127
|
+
end
|
128
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module PaperTrail
|
2
|
+
module ActiveRecord
|
3
|
+
class Configuration
|
4
|
+
def initialize
|
5
|
+
config = self
|
6
|
+
|
7
|
+
config.versions_extends = []
|
8
|
+
end
|
9
|
+
|
10
|
+
# Causes methods that return a collection of Versions to automatically extend these modules.
|
11
|
+
# config.versions_extends = [Versions]
|
12
|
+
attr_accessor :versions_extends
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
module PaperTrail::ActiveRecord
|
2
|
+
|
3
|
+
# If you include this module into a model, it will automatically add a `{association}_or_deleted`
|
4
|
+
# method for every `belongs_to` or `has_one` association that is defined.
|
5
|
+
#
|
6
|
+
# Because it reflects on all associations on that model as soon as it is included, make sure to
|
7
|
+
# include it *after* all of your associations are defined.
|
8
|
+
#
|
9
|
+
# If you want more control, and don't want it to add anything automatically, you can manually call
|
10
|
+
# `define_assoc_or_deleted :association` for each association that you want to have a
|
11
|
+
# `{association}_or_deleted` method.
|
12
|
+
#
|
13
|
+
# If you want it to automatically be added for all assocations on *all* application models, you can
|
14
|
+
# use [gem 'active_record_include'](https://github.com/TylerRick/active_record_include) like this:
|
15
|
+
#
|
16
|
+
# class ApplicationRecord < ActiveRecord::Base
|
17
|
+
# include_when_connected PaperTrail::ActiveRecord::OrDeleted
|
18
|
+
module OrDeleted
|
19
|
+
extend ActiveSupport::Concern
|
20
|
+
|
21
|
+
module ClassMethods
|
22
|
+
# Defines a `{association}_or_deleted` method for the given association. This method will call
|
23
|
+
# the usual association method to try to find the associated record but if that returns nil,
|
24
|
+
# will fall back to looking for a deleted record from the `versions` history (using
|
25
|
+
# `klass.find_deleted`).
|
26
|
+
#
|
27
|
+
# You can replace the `or_deleted` part with a different suffix using `suffix:` option.
|
28
|
+
#
|
29
|
+
# You can even give it the same name as the existing association method if you want to override
|
30
|
+
# the existing method with one that always falls back to looking for a deleted record.
|
31
|
+
#
|
32
|
+
# class Post
|
33
|
+
# belongs_to :author
|
34
|
+
# # overrides author method with a version that finds deleted if not found
|
35
|
+
# define_assoc_or_deleted :author, suffix: nil
|
36
|
+
#
|
37
|
+
def define_assoc_or_deleted(assoc_name, suffix: 'or_deleted')
|
38
|
+
reflection = reflect_on_association(assoc_name) or raise(ArgumentError, "can't find reflection for #{assoc_name}")
|
39
|
+
method_name = suffix ? "#{assoc_name}_#{suffix}" : assoc_name
|
40
|
+
#begin
|
41
|
+
# puts "Creating #{self.name}.#{method_name} => #{reflection.klass}.find_deleted(#{reflection.foreign_key})"
|
42
|
+
|
43
|
+
prepend(Module.new do
|
44
|
+
define_method method_name do |*args|
|
45
|
+
orig_value =
|
46
|
+
if defined?(super)
|
47
|
+
super(*args)
|
48
|
+
else
|
49
|
+
public_send(reflection.name, *args)
|
50
|
+
end
|
51
|
+
return orig_value if orig_value
|
52
|
+
|
53
|
+
klass =
|
54
|
+
if reflection.polymorphic?
|
55
|
+
public_send(reflection.foreign_type).constantize
|
56
|
+
else
|
57
|
+
reflection.klass
|
58
|
+
end
|
59
|
+
id = public_send(reflection.foreign_key)
|
60
|
+
|
61
|
+
klass.find_deleted(id)
|
62
|
+
end
|
63
|
+
end)
|
64
|
+
|
65
|
+
#rescue
|
66
|
+
# puts "Rescued for #{self.name}.#{reflection.inspect}: #{$!} from #{$!.backtrace.first(5)}"
|
67
|
+
#end
|
68
|
+
end
|
69
|
+
|
70
|
+
def define_assoc_or_deleted_on_all_associations(suffix: 'or_deleted')
|
71
|
+
reflect_on_all_associations.each do |reflection|
|
72
|
+
puts %(#{self}.reflection.name=#{(reflection.name).inspect})
|
73
|
+
next if reflection.collection?
|
74
|
+
|
75
|
+
assoc_name = reflection.name
|
76
|
+
method_name = suffix ? "#{assoc_name}_#{suffix}" : assoc_name
|
77
|
+
next if method_defined?(method_name)
|
78
|
+
|
79
|
+
define_assoc_or_deleted reflection.name, suffix: suffix
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
included do
|
85
|
+
define_assoc_or_deleted_on_all_associations
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module PaperTrail::ActiveRecord
|
2
|
+
module VersionConcernExt
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
module ClassMethods
|
6
|
+
# Returns versions before `obj`.
|
7
|
+
# Same as preceding but uses lteq instead of lt
|
8
|
+
#
|
9
|
+
# @param obj - a `Version` or a timestamp
|
10
|
+
# @param timestamp_arg - boolean - When true, `obj` is a timestamp.
|
11
|
+
# Default: false.
|
12
|
+
# @return `ActiveRecord::Relation`
|
13
|
+
# @api public
|
14
|
+
def preceding_inclusive(obj, timestamp_arg = false)
|
15
|
+
if timestamp_arg != true && primary_key_is_int?
|
16
|
+
return where(arel_table[primary_key].lteq(obj.id)).order(arel_table[primary_key].desc)
|
17
|
+
end
|
18
|
+
|
19
|
+
obj = obj.send(:created_at) if obj.is_a?(self)
|
20
|
+
where(arel_table[:created_at].lteq(obj)).
|
21
|
+
order(timestamp_sort_order("desc"))
|
22
|
+
end
|
23
|
+
|
24
|
+
# Same as between but uses gteq/lteq instead of gt/lt
|
25
|
+
def between_inclusive(start_time, end_time)
|
26
|
+
where(
|
27
|
+
arel_table[:created_at].gteq(start_time).
|
28
|
+
and(arel_table[:created_at].lteq(end_time))
|
29
|
+
).order(timestamp_sort_order)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
included do
|
34
|
+
# Finds versions that had made changes to object on *all* of the given attributes.
|
35
|
+
#
|
36
|
+
# Like built-in where_object_changes but without specifying a value. where_object_changes
|
37
|
+
# apparently can only be used to find where a given attribute was changed to or from a specific
|
38
|
+
# *value*. But sometimes you don't care which value it changed to or from, you just want to find
|
39
|
+
# where it changed at all.
|
40
|
+
scope :where_object_changed, ->(*attr_names) {
|
41
|
+
attr_names.inject(all) do |relation, attr_name|
|
42
|
+
relation.where("object_changes->>#{connection.quote(attr_name)} is not null")
|
43
|
+
end
|
44
|
+
}
|
45
|
+
|
46
|
+
# Finds versions that had made changes to object on *any* of the given attributes.
|
47
|
+
scope :where_object_changed_any, ->(*attr_names) {
|
48
|
+
where_clause = attr_names.
|
49
|
+
map {|attr_name| "object_changes->>#{connection.quote(attr_name)} is not null" }.
|
50
|
+
join(' OR ')
|
51
|
+
where(where_clause)
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
def action
|
56
|
+
case event
|
57
|
+
when 'update'
|
58
|
+
"updated"
|
59
|
+
when 'create'
|
60
|
+
"created"
|
61
|
+
else
|
62
|
+
"#{event}ed"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def item_class
|
67
|
+
item_type.safe_constantize
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
PaperTrail::VersionConcern.class_eval do
|
73
|
+
prepend PaperTrail::ActiveRecord::VersionConcernExt
|
74
|
+
include PaperTrail::ActiveRecord::VersionConcernExt
|
75
|
+
end
|
76
|
+
|
@@ -0,0 +1,39 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "paper_trail/active_record/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "paper_trail-active_record"
|
8
|
+
spec.version = PaperTrail::ActiveRecord.version
|
9
|
+
spec.authors = ["Tyler Rick"]
|
10
|
+
spec.email = ["tyler@tylerrick.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Various ActiveRecord extensions}
|
13
|
+
spec.description = spec.summary
|
14
|
+
spec.homepage = "https://github.com/TylerRick/#{spec.name}"
|
15
|
+
|
16
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
17
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
18
|
+
spec.metadata["changelog_uri"] = "#{spec.metadata["source_code_uri"]}/blob/master/Changelog.md"
|
19
|
+
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
23
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
24
|
+
end
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.add_dependency 'paper_trail'
|
30
|
+
spec.add_dependency 'rails'
|
31
|
+
|
32
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
33
|
+
spec.add_development_dependency 'byebug'
|
34
|
+
spec.add_development_dependency 'pg'
|
35
|
+
spec.add_development_dependency 'rake', '>= 12.3.3'
|
36
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
37
|
+
spec.add_development_dependency 'sqlite3'
|
38
|
+
spec.add_development_dependency 'timecop'
|
39
|
+
end
|
metadata
ADDED
@@ -0,0 +1,189 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: paper_trail-active_record
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tyler Rick
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-04-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: paper_trail
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: byebug
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pg
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 12.3.3
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 12.3.3
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '3.0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: sqlite3
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: timecop
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
description: Various ActiveRecord extensions
|
140
|
+
email:
|
141
|
+
- tyler@tylerrick.com
|
142
|
+
executables: []
|
143
|
+
extensions: []
|
144
|
+
extra_rdoc_files: []
|
145
|
+
files:
|
146
|
+
- ".gitignore"
|
147
|
+
- ".rspec"
|
148
|
+
- ".travis.yml"
|
149
|
+
- ".yardopts"
|
150
|
+
- Changelog.md
|
151
|
+
- Gemfile
|
152
|
+
- License
|
153
|
+
- Rakefile
|
154
|
+
- Readme.md
|
155
|
+
- bin/console
|
156
|
+
- bin/setup
|
157
|
+
- lib/paper_trail/active_record.rb
|
158
|
+
- lib/paper_trail/active_record/base_extensions.rb
|
159
|
+
- lib/paper_trail/active_record/configuration.rb
|
160
|
+
- lib/paper_trail/active_record/or_deleted.rb
|
161
|
+
- lib/paper_trail/active_record/version.rb
|
162
|
+
- lib/paper_trail/active_record/version_extensions.rb
|
163
|
+
- paper_trail-active_record.gemspec
|
164
|
+
homepage: https://github.com/TylerRick/paper_trail-active_record
|
165
|
+
licenses: []
|
166
|
+
metadata:
|
167
|
+
homepage_uri: https://github.com/TylerRick/paper_trail-active_record
|
168
|
+
source_code_uri: https://github.com/TylerRick/paper_trail-active_record
|
169
|
+
changelog_uri: https://github.com/TylerRick/paper_trail-active_record/blob/master/Changelog.md
|
170
|
+
post_install_message:
|
171
|
+
rdoc_options: []
|
172
|
+
require_paths:
|
173
|
+
- lib
|
174
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
175
|
+
requirements:
|
176
|
+
- - ">="
|
177
|
+
- !ruby/object:Gem::Version
|
178
|
+
version: '0'
|
179
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
180
|
+
requirements:
|
181
|
+
- - ">="
|
182
|
+
- !ruby/object:Gem::Version
|
183
|
+
version: '0'
|
184
|
+
requirements: []
|
185
|
+
rubygems_version: 3.0.3
|
186
|
+
signing_key:
|
187
|
+
specification_version: 4
|
188
|
+
summary: Various ActiveRecord extensions
|
189
|
+
test_files: []
|