acts_as_trackable 0.2.5 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +4 -4
- data/README.md +12 -0
- data/changelog.md +7 -0
- data/lib/acts_as_trackable/trackable.rb +11 -1
- data/lib/acts_as_trackable/version.rb +1 -1
- data/lib/acts_as_trackable.rb +16 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d5bb2629a59e7f11d52350b0bb6bbc994685330a1e047d0263b6f1f7ef6158f1
|
4
|
+
data.tar.gz: f99f747270c0954dc5fd635cc1063a38df43d3d07bbd782f85f3d984aaf9673d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76482ee95e44272d123d88c9a2d99a3d240efe80d677a88ad7d5b1ad2134755c02a3b5b6399a1e40d83bce4318c04fb95c5ee9a8bc0cc13aacf10791ee91cde0
|
7
|
+
data.tar.gz: 4312bb8bbde9fbcfdc758e9589fb1af383d00b3d41fe99e0251f9ce11d11fe1417175568842cb25627704dca4630871f87979077327d715d8dcdd129842e47e3
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
acts_as_trackable (0.
|
4
|
+
acts_as_trackable (0.3.1)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -65,10 +65,10 @@ GEM
|
|
65
65
|
loofah (2.24.0)
|
66
66
|
crass (~> 1.0.2)
|
67
67
|
nokogiri (>= 1.12.0)
|
68
|
-
minitest (5.25.
|
69
|
-
nokogiri (1.18.
|
68
|
+
minitest (5.25.5)
|
69
|
+
nokogiri (1.18.5-arm64-darwin)
|
70
70
|
racc (~> 1.4)
|
71
|
-
nokogiri (1.18.
|
71
|
+
nokogiri (1.18.5-x86_64-darwin)
|
72
72
|
racc (~> 1.4)
|
73
73
|
pp (0.6.2)
|
74
74
|
prettyprint
|
data/README.md
CHANGED
@@ -45,6 +45,18 @@ After that run the following commands:
|
|
45
45
|
```ruby
|
46
46
|
acts_as_modifier
|
47
47
|
```
|
48
|
+
- For STI models, set the following attribute to true to save the child class's object type as the parent class's (base_class) object type:
|
49
|
+
```ruby
|
50
|
+
class Post < ActiveRecord::Base
|
51
|
+
self.inheritance_column = :class_name
|
52
|
+
|
53
|
+
acts_as_trackable
|
54
|
+
end
|
55
|
+
|
56
|
+
class Comment < Post
|
57
|
+
acts_as_trackable fallback_to_base_class: true
|
58
|
+
end
|
59
|
+
```
|
48
60
|
- After that, you need to pass the user to the modifier attribute from your controller(or basically anywhere) to your update/create statements as follows(If you don't pass the modifier, track me will simply ignore creating/updating the object activity):
|
49
61
|
```ruby
|
50
62
|
YourTrackableModel.update(modifier: @current_user)
|
data/changelog.md
CHANGED
@@ -1,4 +1,11 @@
|
|
1
1
|
# acts_as_trackable Changelog
|
2
|
+
## Version: 0.3.1
|
3
|
+
### Patch
|
4
|
+
- Updated README
|
5
|
+
## Version: 0.3.0
|
6
|
+
### Patch
|
7
|
+
- Added support to treat STI models as one model
|
8
|
+
- Upgraded dependencies to patch CVE-2025-24855 and CVE-2024-55549
|
2
9
|
## Version: 0.2.5
|
3
10
|
### Patch
|
4
11
|
- Upgraded dependencies to patch CVE-2025-27111 and CVE-2025-27610
|
@@ -8,6 +8,10 @@ module Trackable
|
|
8
8
|
|
9
9
|
has_one :object_activity, as: :object, dependent: :destroy
|
10
10
|
|
11
|
+
define_method :object_activity do
|
12
|
+
ObjectActivity.find_by('object_id = ? AND (object_type = ? OR object_type = ?)', id, self.class.name, self.class.base_class.name)
|
13
|
+
end
|
14
|
+
|
11
15
|
delegate :created_by, :updated_by, to: :object_activity, allow_nil: true
|
12
16
|
|
13
17
|
after_commit :log_object_activity, on: %i[create update], if: -> { modifier.present? }
|
@@ -44,7 +48,13 @@ module Trackable
|
|
44
48
|
end
|
45
49
|
|
46
50
|
def trackable_object
|
47
|
-
|
51
|
+
class_name = if self.class.fallback_to_base_class
|
52
|
+
self.class.base_class.name
|
53
|
+
else
|
54
|
+
self.class.name
|
55
|
+
end
|
56
|
+
|
57
|
+
{ object_id: send(self.class.trackable_column), object_type: class_name }
|
48
58
|
end
|
49
59
|
end
|
50
60
|
end
|
data/lib/acts_as_trackable.rb
CHANGED
@@ -8,13 +8,14 @@ module ActsAsTrackable
|
|
8
8
|
extend ActiveSupport::Concern
|
9
9
|
|
10
10
|
included do
|
11
|
-
class_attribute :trackable_column
|
11
|
+
class_attribute :trackable_column, :fallback_to_base_class
|
12
12
|
end
|
13
13
|
|
14
14
|
class_methods do
|
15
|
-
def acts_as_trackable(column_name = :id)
|
16
|
-
self.trackable_column
|
17
|
-
|
15
|
+
def acts_as_trackable(column_name = :id, fallback_to_base_class: false)
|
16
|
+
self.trackable_column = column_name
|
17
|
+
self.fallback_to_base_class = fallback_to_base_class
|
18
|
+
validate_attributes
|
18
19
|
include Trackable
|
19
20
|
end
|
20
21
|
|
@@ -24,11 +25,22 @@ module ActsAsTrackable
|
|
24
25
|
|
25
26
|
private
|
26
27
|
|
28
|
+
def validate_attributes
|
29
|
+
validate_trackable_column
|
30
|
+
validate_fallback_to_base_class
|
31
|
+
end
|
32
|
+
|
27
33
|
def validate_trackable_column
|
28
34
|
return if column_names.include?(trackable_column.to_s)
|
29
35
|
|
30
36
|
raise ArgumentError, "Column '#{trackable_column}' does not exist in the table"
|
31
37
|
end
|
38
|
+
|
39
|
+
def validate_fallback_to_base_class
|
40
|
+
return if fallback_to_base_class.nil? || [true, false].include?(fallback_to_base_class)
|
41
|
+
|
42
|
+
raise ArgumentError, 'fallback_to_base_class must be a boolean'
|
43
|
+
end
|
32
44
|
end
|
33
45
|
end
|
34
46
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_trackable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ahmad Keewan
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2025-03-
|
12
|
+
date: 2025-03-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: generator_spec
|