paper_trail-active_record 0.1.1 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e424c0dbb41ccae430a47d5edbdaaf42267f4789c9bda011c50e97841a8b3596
4
- data.tar.gz: 89a7021a5fa8141ddc07167c6f7ee8ce1e04ca64135dee976b9e730c89e3773d
3
+ metadata.gz: 7eb43efab491ca147042d869e1c6cb393f93aeb0009b0d4cb07cbd2bf53a6f86
4
+ data.tar.gz: 2dbd8283253a607fafca24f701a3301370e68a297b268dfafb6860a695fc21c0
5
5
  SHA512:
6
- metadata.gz: 8d2e504931134b961b3c750312e80f14e00909cb3fbfab616c0fdc6ff08de6bd9388de86bad8861022980c7f6737c4964fe7d144986167a89c3719b24f79b097
7
- data.tar.gz: '093d5bcb1f5f59e0753d19f30c7564f48ccea1408bea59b056c84325e52351a93c175666b072f3fbff33d0cf8a9f34c62b8937cac2ea86419c0937db4f719631'
6
+ metadata.gz: 1d51610af16be9fe0c8963194c41e218fa5a1dd3916c22d15e7c7fea6a2e137f3d87da649f7cee471b65267c195150ca5bdaed4d32b35624b5f05d2d4632b718
7
+ data.tar.gz: 64ada7b475c0594cff53556e7c703fbf07a91af9106bb0d3e504ef9a22729427ce753f65a30a99bdca6ac05e3c06c278b6d6caf7a6c29d447dab5f5028c2f188
data/Changelog.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## 1.0.0 (2022-04-27)
2
+
3
+ Breaking changes:
4
+ - `PaperTrail::ActiveRecord` was renamed to `PaperTrail::ActiveRecordExt` to fix this error with paper_trail 12.3.0 / rails 7:
5
+
6
+ NameError:
7
+ uninitialized constant PaperTrail::ActiveRecord::Type
8
+
9
+ elsif PaperTrail::RAILS_GTE_7_0 && val.is_a?(ActiveRecord::Type::Time::Value)
10
+
11
+ ## 0.1.2 (2020-04-27)
12
+
13
+ - Fix: Remove debug output
14
+
1
15
  ## 0.1.1 (2020-04-23)
2
16
 
3
17
  - Fix: `has_many_versions` was passing wrong value for extends
data/Readme.md CHANGED
@@ -1,10 +1,10 @@
1
- # PaperTrail::ActiveRecord
1
+ # PaperTrail::ActiveRecordExt
2
2
 
3
3
  [![Gem Version][1]][2]
4
4
  [![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](https://rdoc.info/github/TylerRick/paper_trail-active_record/master)
5
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.
6
+ Various ActiveRecord extensions to make your life easier when working with
7
+ [PaperTrail](https://github.com/paper-trail-gem/paper_trail) versions and versioned model records.
8
8
 
9
9
  ## Methods added to models with `has_paper_trail`
10
10
 
@@ -27,25 +27,7 @@ that adds some useful extensions to models that have `has_paper_trail` and to th
27
27
  - `#action`
28
28
  - `#item_class`
29
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
- ```
30
+ ## `{association}_or_deleted`
49
31
 
50
32
  ### `def define_assoc_or_deleted(assoc_name, suffix: nil)`
51
33
 
@@ -66,6 +48,23 @@ class Post
66
48
  define_assoc_or_deleted :author, suffix: nil
67
49
  ```
68
50
 
51
+ ### Automatically add for all assocations
52
+
53
+ If you include `PaperTrail::ActiveRecordExt::OrDeleted` into a model, it will automatically add a `{association}_or_deleted`
54
+ method for every `belongs_to` or `has_one` association that is defined.
55
+
56
+ Because it reflects on all associations on that model as soon as it is included, make sure to
57
+ include it *after* all of your associations are defined. You can also call
58
+ `define_assoc_or_deleted_on_all_associations` at the end of your model class (that is the same
59
+ method that including the module triggers).
60
+
61
+ If you want it to automatically be added for all assocations on *all* application models, you can
62
+ use [gem 'active_record_include'](https://github.com/TylerRick/active_record_include) like this:
63
+
64
+ ```ruby
65
+ class ApplicationRecord < ActiveRecord::Base
66
+ include_when_connected PaperTrail::ActiveRecordExt::OrDeleted
67
+ ```
69
68
 
70
69
 
71
70
  ## Installation
data/bin/console CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "bundler/setup"
4
- require "paper_trail/rails"
4
+ require "paper_trail/active_record"
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
@@ -1,4 +1,4 @@
1
- module PaperTrail::ActiveRecord
1
+ module PaperTrail::ActiveRecordExt
2
2
 
3
3
  # Extensions to ActiveRecord::Base to better support PaperTrail
4
4
  module BaseExtensions
@@ -13,7 +13,7 @@ module BaseExtensions
13
13
  else
14
14
  Version.where(item_type: base_class.name, item_subtype: self.name)
15
15
  end.tap do |versions|
16
- PaperTrail::ActiveRecord.config.versions_extends.each do |mod|
16
+ PaperTrail::ActiveRecordExt.config.versions_extends.each do |mod|
17
17
  versions.extend(mod)
18
18
  end
19
19
  end
@@ -51,7 +51,7 @@ module BaseExtensions
51
51
  end
52
52
 
53
53
  def has_many_versions(name, *args, **options)
54
- has_many name, *args, class_name: 'Version', extend: PaperTrail::ActiveRecord.config.versions_extends, **options
54
+ has_many name, *args, class_name: 'Version', extend: PaperTrail::ActiveRecordExt.config.versions_extends, **options
55
55
  end
56
56
 
57
57
  # Creates associations for finding related versions — that is, versions for related/children
@@ -123,6 +123,6 @@ end
123
123
  end
124
124
 
125
125
  ActiveRecord::Base.class_eval do
126
- include PaperTrail::ActiveRecord::BaseExtensions
126
+ include PaperTrail::ActiveRecordExt::BaseExtensions
127
127
  end
128
128
 
@@ -1,5 +1,5 @@
1
1
  module PaperTrail
2
- module ActiveRecord
2
+ module ActiveRecordExt
3
3
  class Configuration
4
4
  def initialize
5
5
  config = self
@@ -1,4 +1,4 @@
1
- module PaperTrail::ActiveRecord
1
+ module PaperTrail::ActiveRecordExt
2
2
 
3
3
  # If you include this module into a model, it will automatically add a `{association}_or_deleted`
4
4
  # method for every `belongs_to` or `has_one` association that is defined.
@@ -52,13 +52,13 @@ module OrDeleted
52
52
 
53
53
  klass =
54
54
  if reflection.polymorphic?
55
- public_send(reflection.foreign_type).constantize
55
+ public_send(reflection.foreign_type)&.constantize
56
56
  else
57
57
  reflection.klass
58
58
  end
59
59
  id = public_send(reflection.foreign_key)
60
60
 
61
- klass.find_deleted(id)
61
+ klass&.find_deleted(id) if id
62
62
  end
63
63
  end)
64
64
 
@@ -69,7 +69,7 @@ module OrDeleted
69
69
 
70
70
  def define_assoc_or_deleted_on_all_associations(suffix: 'or_deleted')
71
71
  reflect_on_all_associations.each do |reflection|
72
- puts %(#{self}.reflection.name=#{(reflection.name).inspect})
72
+ #puts %(#{self}.reflection.name=#{(reflection.name).inspect})
73
73
  next if reflection.collection?
74
74
 
75
75
  assoc_name = reflection.name
@@ -1,7 +1,7 @@
1
1
  module PaperTrail
2
- module ActiveRecord
2
+ module ActiveRecordExt
3
3
  def self.version
4
- "0.1.1"
4
+ "1.0.1"
5
5
  end
6
6
  end
7
7
  end
@@ -1,4 +1,6 @@
1
- module PaperTrail::ActiveRecord
1
+ require 'paper_trail/version_concern'
2
+
3
+ module PaperTrail::ActiveRecordExt
2
4
  module VersionConcernExt
3
5
  extend ActiveSupport::Concern
4
6
 
@@ -70,7 +72,7 @@ end
70
72
  end
71
73
 
72
74
  PaperTrail::VersionConcern.class_eval do
73
- prepend PaperTrail::ActiveRecord::VersionConcernExt
74
- include PaperTrail::ActiveRecord::VersionConcernExt
75
+ prepend PaperTrail::ActiveRecordExt::VersionConcernExt
76
+ include PaperTrail::ActiveRecordExt::VersionConcernExt
75
77
  end
76
78
 
@@ -1,4 +1,6 @@
1
+ require 'active_record'
1
2
  require 'paper_trail'
3
+ require 'paper_trail/frameworks/active_record'
2
4
 
3
5
  require_relative 'active_record/version'
4
6
 
@@ -8,7 +10,7 @@ require_relative 'active_record/or_deleted'
8
10
  require_relative 'active_record/version_extensions'
9
11
 
10
12
  module PaperTrail
11
- module ActiveRecord
13
+ module ActiveRecordExt
12
14
  class << self
13
15
  def configuration
14
16
  @configuration ||= Configuration.new
@@ -5,11 +5,11 @@ require "paper_trail/active_record/version"
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "paper_trail-active_record"
8
- spec.version = PaperTrail::ActiveRecord.version
8
+ spec.version = PaperTrail::ActiveRecordExt.version
9
9
  spec.authors = ["Tyler Rick"]
10
10
  spec.email = ["tyler@tylerrick.com"]
11
11
 
12
- spec.summary = %q{Various ActiveRecord extensions}
12
+ spec.summary = %q{Various ActiveRecord extensions to make your life easier when working with PaperTrail versions}
13
13
  spec.description = spec.summary
14
14
  spec.homepage = "https://github.com/TylerRick/#{spec.name}"
15
15
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paper_trail-active_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Rick
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-04-24 00:00:00.000000000 Z
11
+ date: 2022-06-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: paper_trail
@@ -136,7 +136,8 @@ dependencies:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
- description: Various ActiveRecord extensions
139
+ description: Various ActiveRecord extensions to make your life easier when working
140
+ with PaperTrail versions
140
141
  email:
141
142
  - tyler@tylerrick.com
142
143
  executables: []
@@ -182,8 +183,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
182
183
  - !ruby/object:Gem::Version
183
184
  version: '0'
184
185
  requirements: []
185
- rubygems_version: 3.0.3
186
+ rubygems_version: 3.3.3
186
187
  signing_key:
187
188
  specification_version: 4
188
- summary: Various ActiveRecord extensions
189
+ summary: Various ActiveRecord extensions to make your life easier when working with
190
+ PaperTrail versions
189
191
  test_files: []