acts_as_trackable 0.1.0
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 +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.ruby-version +1 -0
- data/.travis.yml +6 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +88 -0
- data/LICENSE.txt +21 -0
- data/README.md +74 -0
- data/Rakefile +6 -0
- data/acts_as_trackable.gemspec +40 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/acts_as_trackable/modifier.rb +10 -0
- data/lib/acts_as_trackable/trackable.rb +50 -0
- data/lib/acts_as_trackable/version.rb +3 -0
- data/lib/acts_as_trackable.rb +37 -0
- data/lib/generators/acts_as_trackable/object_activity_generator.rb +22 -0
- data/lib/generators/acts_as_trackable/templates/create_object_activity.rb +10 -0
- data/lib/generators/acts_as_trackable/templates/object_activity.rb +7 -0
- metadata +89 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: a700b0c0fba945f6c9876467d413d0600f0a2ab74d99972056dfe927748db138
|
|
4
|
+
data.tar.gz: 9418887b082a2b132aeccd35141195399199b9ad434cbe89deaaeb29504a4e78
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: a1f834409c983cd6edec2afa8f15fcd6d1d1d18d918aba0b00d7fa75c5d31c04d4404903b4980256d31882a3b9a8c6bcdc268f3665029b2c83c09dcc9b03e401
|
|
7
|
+
data.tar.gz: 0f0c6826c985e4b8de63c2144d2971a6aac46ffb32d1202623e55cefa4e9fa1091358770d60a36254b78bdc1d705be11ece697c3b19c2ae25981596b3d1cb2b5
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
2.7.2
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
|
10
|
+
orientation.
|
|
11
|
+
|
|
12
|
+
## Our Standards
|
|
13
|
+
|
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
|
15
|
+
include:
|
|
16
|
+
|
|
17
|
+
* Using welcoming and inclusive language
|
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
|
19
|
+
* Gracefully accepting constructive criticism
|
|
20
|
+
* Focusing on what is best for the community
|
|
21
|
+
* Showing empathy towards other community members
|
|
22
|
+
|
|
23
|
+
Examples of unacceptable behavior by participants include:
|
|
24
|
+
|
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
26
|
+
advances
|
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
28
|
+
* Public or private harassment
|
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
|
30
|
+
address, without explicit permission
|
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
32
|
+
professional setting
|
|
33
|
+
|
|
34
|
+
## Our Responsibilities
|
|
35
|
+
|
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
|
38
|
+
response to any instances of unacceptable behavior.
|
|
39
|
+
|
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
44
|
+
threatening, offensive, or harmful.
|
|
45
|
+
|
|
46
|
+
## Scope
|
|
47
|
+
|
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
|
49
|
+
when an individual is representing the project or its community. Examples of
|
|
50
|
+
representing a project or community include using an official project e-mail
|
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
|
53
|
+
further defined and clarified by project maintainers.
|
|
54
|
+
|
|
55
|
+
## Enforcement
|
|
56
|
+
|
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
58
|
+
reported by contacting the project team at a.keewan@zenhr.com. All
|
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
|
63
|
+
|
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
|
66
|
+
members of the project's leadership.
|
|
67
|
+
|
|
68
|
+
## Attribution
|
|
69
|
+
|
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
|
72
|
+
|
|
73
|
+
[homepage]: https://contributor-covenant.org
|
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
acts_as_trackable (0.1.0)
|
|
5
|
+
|
|
6
|
+
GEM
|
|
7
|
+
remote: https://rubygems.org/
|
|
8
|
+
specs:
|
|
9
|
+
actionpack (6.1.7.10)
|
|
10
|
+
actionview (= 6.1.7.10)
|
|
11
|
+
activesupport (= 6.1.7.10)
|
|
12
|
+
rack (~> 2.0, >= 2.0.9)
|
|
13
|
+
rack-test (>= 0.6.3)
|
|
14
|
+
rails-dom-testing (~> 2.0)
|
|
15
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
|
16
|
+
actionview (6.1.7.10)
|
|
17
|
+
activesupport (= 6.1.7.10)
|
|
18
|
+
builder (~> 3.1)
|
|
19
|
+
erubi (~> 1.4)
|
|
20
|
+
rails-dom-testing (~> 2.0)
|
|
21
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
|
22
|
+
activemodel (6.1.7.10)
|
|
23
|
+
activesupport (= 6.1.7.10)
|
|
24
|
+
activerecord (6.1.7.10)
|
|
25
|
+
activemodel (= 6.1.7.10)
|
|
26
|
+
activesupport (= 6.1.7.10)
|
|
27
|
+
activesupport (6.1.7.10)
|
|
28
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
29
|
+
i18n (>= 1.6, < 2)
|
|
30
|
+
minitest (>= 5.1)
|
|
31
|
+
tzinfo (~> 2.0)
|
|
32
|
+
zeitwerk (~> 2.3)
|
|
33
|
+
builder (3.3.0)
|
|
34
|
+
concurrent-ruby (1.3.4)
|
|
35
|
+
crass (1.0.6)
|
|
36
|
+
erubi (1.13.0)
|
|
37
|
+
generator_spec (0.10.0)
|
|
38
|
+
activesupport (>= 3.0.0)
|
|
39
|
+
railties (>= 3.0.0)
|
|
40
|
+
i18n (1.14.6)
|
|
41
|
+
concurrent-ruby (~> 1.0)
|
|
42
|
+
loofah (2.23.1)
|
|
43
|
+
crass (~> 1.0.2)
|
|
44
|
+
nokogiri (>= 1.12.0)
|
|
45
|
+
method_source (1.1.0)
|
|
46
|
+
mini_portile2 (2.8.8)
|
|
47
|
+
minitest (5.25.1)
|
|
48
|
+
nokogiri (1.15.6)
|
|
49
|
+
mini_portile2 (~> 2.8.2)
|
|
50
|
+
racc (~> 1.4)
|
|
51
|
+
racc (1.8.1)
|
|
52
|
+
rack (2.2.10)
|
|
53
|
+
rack-test (2.1.0)
|
|
54
|
+
rack (>= 1.3)
|
|
55
|
+
rails-dom-testing (2.2.0)
|
|
56
|
+
activesupport (>= 5.0.0)
|
|
57
|
+
minitest
|
|
58
|
+
nokogiri (>= 1.6)
|
|
59
|
+
rails-html-sanitizer (1.6.0)
|
|
60
|
+
loofah (~> 2.21)
|
|
61
|
+
nokogiri (~> 1.14)
|
|
62
|
+
railties (6.1.7.10)
|
|
63
|
+
actionpack (= 6.1.7.10)
|
|
64
|
+
activesupport (= 6.1.7.10)
|
|
65
|
+
method_source
|
|
66
|
+
rake (>= 12.2)
|
|
67
|
+
thor (~> 1.0)
|
|
68
|
+
rake (13.2.1)
|
|
69
|
+
sqlite3 (1.6.9)
|
|
70
|
+
mini_portile2 (~> 2.8.0)
|
|
71
|
+
thor (1.3.2)
|
|
72
|
+
tzinfo (2.0.6)
|
|
73
|
+
concurrent-ruby (~> 1.0)
|
|
74
|
+
zeitwerk (2.6.18)
|
|
75
|
+
|
|
76
|
+
PLATFORMS
|
|
77
|
+
ruby
|
|
78
|
+
|
|
79
|
+
DEPENDENCIES
|
|
80
|
+
activerecord (~> 6.1, >= 6.1.7.10)
|
|
81
|
+
activesupport (~> 6.1, >= 6.1.7.10)
|
|
82
|
+
acts_as_trackable!
|
|
83
|
+
generator_spec
|
|
84
|
+
rake (~> 13.2.1)
|
|
85
|
+
sqlite3 (~> 1.6.8)
|
|
86
|
+
|
|
87
|
+
BUNDLED WITH
|
|
88
|
+
2.1.4
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Ahmad Keewan - ZenHR Engineering
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
<!-- [](https://badge.fury.io/rb/acts_as_trackable) -->
|
|
2
|
+
|
|
3
|
+
# ActsAsTrackable
|
|
4
|
+
|
|
5
|
+
ActsAsTrackable is a gem that simplifies the process of tracking your DB object's creation and modification.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Add this line to your application's Gemfile(For now you have to add it locally v0.1.0):
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
gem 'acts_as_trackable', path: 'path_to_gem'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
And then execute:
|
|
16
|
+
|
|
17
|
+
$ bundle install
|
|
18
|
+
|
|
19
|
+
Or install it yourself as:
|
|
20
|
+
|
|
21
|
+
$ gem install acts_as_trackable
|
|
22
|
+
|
|
23
|
+
After that run the following commands:
|
|
24
|
+
|
|
25
|
+
$ rails generate acts_as_trackable:object_activity ObjectActivity
|
|
26
|
+
$ rails db:migrate
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
- ActsAsTrackable is auto_loaded, there's no need to add it to ApplicationRecord.rb
|
|
31
|
+
|
|
32
|
+
- Go to your model and add the following:
|
|
33
|
+
|
|
34
|
+
```ruby
|
|
35
|
+
acts_as_trackable
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
- If your model is expected to have multiple version of each object, pass the column that tracks the version to acts_as_trackable as a symbol, acts_as_trackable is smart enough to relink the object_activity with the latest version(Previous versions won't be linked to any activity):
|
|
39
|
+
|
|
40
|
+
```ruby
|
|
41
|
+
acts_as_trackable :latest_x_version_id
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
- Go to your user model and the following:
|
|
45
|
+
```ruby
|
|
46
|
+
acts_as_modifier
|
|
47
|
+
```
|
|
48
|
+
- 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
|
+
```ruby
|
|
50
|
+
YourTrackableModel.update(modifier: @current_user)
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
- Joining your records with objects_activities:
|
|
55
|
+
```ruby
|
|
56
|
+
@records.left_joins_object_activities(['YourUserModelClassName'])
|
|
57
|
+
```
|
|
58
|
+
## Development
|
|
59
|
+
|
|
60
|
+
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.
|
|
61
|
+
|
|
62
|
+
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).
|
|
63
|
+
|
|
64
|
+
## Contributing
|
|
65
|
+
|
|
66
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/a-keewan/acts_as_trackable. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/acts_as_trackable/blob/master/CODE_OF_CONDUCT.md).
|
|
67
|
+
|
|
68
|
+
## License
|
|
69
|
+
|
|
70
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
71
|
+
|
|
72
|
+
## Code of Conduct
|
|
73
|
+
|
|
74
|
+
Everyone interacting in the ActsAsTrackable project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/a-keewan/acts_as_trackable/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
require_relative 'lib/acts_as_trackable/version'
|
|
2
|
+
|
|
3
|
+
Gem::Specification.new do |spec|
|
|
4
|
+
spec.name = 'acts_as_trackable'
|
|
5
|
+
spec.version = ActsAsTrackable::VERSION
|
|
6
|
+
spec.authors = ['Ahmad Keewan', 'ZenHR Engineering']
|
|
7
|
+
spec.email = ['a.keewan@zenhr.com']
|
|
8
|
+
spec.homepage = 'https://www.zenhr.com'
|
|
9
|
+
spec.license = 'MIT'
|
|
10
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.7.2')
|
|
11
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
12
|
+
spec.metadata["source_code_uri"] = 'https://github.com/a-keewan/acts_as_trackable'
|
|
13
|
+
spec.metadata["changelog_uri"] = 'https://github.com/a-keewan/acts_as_trackable/blob/master/changelog.md'
|
|
14
|
+
|
|
15
|
+
spec.summary = <<~DESC
|
|
16
|
+
ActsAsTrackable is a RoR gem that simplifies tracking the creation and modification of database objects.
|
|
17
|
+
It provides easy-to-use methods to make any ActiveRecord model trackable
|
|
18
|
+
and allows tracking of modifications by specific users.
|
|
19
|
+
DESC
|
|
20
|
+
spec.description = <<~DESC
|
|
21
|
+
ActsAsTrackable is designed to simplify the process of tracking database object activities in Ruby on Rails applications.
|
|
22
|
+
By including the gem and running a few setup commands, developers can make their models trackable with minimal effort.
|
|
23
|
+
The gem supports tracking multiple versions of objects and associating activities with specific users.
|
|
24
|
+
It is auto-loaded into ActiveRecord, eliminating the need for manual inclusion in models.
|
|
25
|
+
ActsAsTrackable also provides methods for joining records with their associated activities,
|
|
26
|
+
making it easier to query and analyze object changes.
|
|
27
|
+
DESC
|
|
28
|
+
|
|
29
|
+
# Specify which files should be added to the gem when it is released.
|
|
30
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
31
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
|
32
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) || f.end_with?('.gem') }
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
spec.add_development_dependency 'generator_spec'
|
|
36
|
+
|
|
37
|
+
spec.bindir = 'exe'
|
|
38
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
39
|
+
spec.require_paths = ['lib']
|
|
40
|
+
end
|
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "acts_as_trackable"
|
|
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,10 @@
|
|
|
1
|
+
require 'active_support/concern'
|
|
2
|
+
|
|
3
|
+
module Modifier
|
|
4
|
+
extend ActiveSupport::Concern
|
|
5
|
+
|
|
6
|
+
included do
|
|
7
|
+
has_many :object_activities_as_updater, class_name: 'ObjectActivity', as: :updated_by
|
|
8
|
+
has_many :object_activities_as_creator, class_name: 'ObjectActivity', as: :created_by
|
|
9
|
+
end
|
|
10
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
require 'active_support/concern'
|
|
2
|
+
|
|
3
|
+
module Trackable
|
|
4
|
+
extend ActiveSupport::Concern
|
|
5
|
+
|
|
6
|
+
included do
|
|
7
|
+
attr_accessor :modifier
|
|
8
|
+
|
|
9
|
+
has_one :object_activity, as: :object, dependent: :destroy
|
|
10
|
+
|
|
11
|
+
delegate :created_by, :updated_by, to: :object_activity, allow_nil: true
|
|
12
|
+
|
|
13
|
+
after_commit :log_object_activity, on: %i[create update], if: -> { modifier.present? }
|
|
14
|
+
|
|
15
|
+
scope :left_joins_object_activities, lambda { |user_types|
|
|
16
|
+
query = left_joins(:object_activity)
|
|
17
|
+
user_types.each do |user_type|
|
|
18
|
+
query = query.joins(left_join_users('created_by', user_type))
|
|
19
|
+
.joins(left_join_users('updated_by', user_type))
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
query
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
def self.left_join_users(action, user_type)
|
|
26
|
+
"LEFT JOIN #{user_type.downcase.pluralize} AS #{action}_#{user_type.downcase.pluralize} " \
|
|
27
|
+
"ON #{action}_#{user_type.downcase.pluralize}.id = object_activities.#{action}_id " \
|
|
28
|
+
"AND object_activities.#{action}_type = '#{user_type}'"
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
private
|
|
32
|
+
|
|
33
|
+
def log_object_activity
|
|
34
|
+
object_activity = ObjectActivity.find_or_initialize_by(trackable_object)
|
|
35
|
+
object_activity.object_id = id
|
|
36
|
+
object_activity.created_by ||= modifier
|
|
37
|
+
|
|
38
|
+
if object_activity.persisted?
|
|
39
|
+
object_activity.updated_by = modifier
|
|
40
|
+
object_activity.updated_at = Time.current
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
object_activity.save!
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def trackable_object
|
|
47
|
+
{ object_id: send(self.class.trackable_column), object_type: self.class.name }
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
require_relative 'acts_as_trackable/version'
|
|
2
|
+
require_relative 'acts_as_trackable/trackable'
|
|
3
|
+
require_relative 'acts_as_trackable/modifier'
|
|
4
|
+
|
|
5
|
+
module ActsAsTrackable
|
|
6
|
+
class Error < StandardError; end
|
|
7
|
+
|
|
8
|
+
extend ActiveSupport::Concern
|
|
9
|
+
|
|
10
|
+
included do
|
|
11
|
+
class_attribute :trackable_column
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
class_methods do
|
|
15
|
+
def acts_as_trackable(column_name = :id)
|
|
16
|
+
self.trackable_column = column_name
|
|
17
|
+
validate_trackable_column
|
|
18
|
+
include Trackable
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def acts_as_modifier
|
|
22
|
+
include Modifier
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
def validate_trackable_column
|
|
28
|
+
return if column_names.include?(trackable_column.to_s)
|
|
29
|
+
|
|
30
|
+
raise ArgumentError, "Column '#{trackable_column}' does not exist in the table"
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
ActiveSupport.on_load(:active_record) do
|
|
36
|
+
include ActsAsTrackable
|
|
37
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require 'rails/generators/active_record'
|
|
2
|
+
require 'rails/generators/named_base'
|
|
3
|
+
|
|
4
|
+
module ActsAsTrackable
|
|
5
|
+
module Generators
|
|
6
|
+
class ObjectActivityGenerator < Rails::Generators::NamedBase
|
|
7
|
+
source_root File.expand_path('templates', __dir__)
|
|
8
|
+
|
|
9
|
+
def create_migration
|
|
10
|
+
migration_file_name = "create_object_activity.rb"
|
|
11
|
+
timestamp = Time.now.utc.strftime("%Y%m%d%H%M%S")
|
|
12
|
+
destination = File.join('db', 'migrate', "#{timestamp}_#{migration_file_name}")
|
|
13
|
+
|
|
14
|
+
template migration_file_name, destination
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def create_model_file
|
|
18
|
+
template 'object_activity.rb', File.join('app/models', class_path, "#{file_name}.rb")
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
class CreateObjectActivity < ActiveRecord::Migration[6.1]
|
|
2
|
+
def change
|
|
3
|
+
create_table :object_activities do |t|
|
|
4
|
+
t.references :object, polymorphic: true, index: true, null: false
|
|
5
|
+
t.references :created_by, polymorphic: true, index: true, null: false
|
|
6
|
+
t.references :updated_by, polymorphic: true, index: true
|
|
7
|
+
t.datetime :updated_at
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: acts_as_trackable
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Ahmad Keewan
|
|
8
|
+
- ZenHR Engineering
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: exe
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2024-11-17 00:00:00.000000000 Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: generator_spec
|
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
|
17
|
+
requirements:
|
|
18
|
+
- - ">="
|
|
19
|
+
- !ruby/object:Gem::Version
|
|
20
|
+
version: '0'
|
|
21
|
+
type: :development
|
|
22
|
+
prerelease: false
|
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
24
|
+
requirements:
|
|
25
|
+
- - ">="
|
|
26
|
+
- !ruby/object:Gem::Version
|
|
27
|
+
version: '0'
|
|
28
|
+
description: |
|
|
29
|
+
ActsAsTrackable is designed to simplify the process of tracking database object activities in Ruby on Rails applications.
|
|
30
|
+
By including the gem and running a few setup commands, developers can make their models trackable with minimal effort.
|
|
31
|
+
The gem supports tracking multiple versions of objects and associating activities with specific users.
|
|
32
|
+
It is auto-loaded into ActiveRecord, eliminating the need for manual inclusion in models.
|
|
33
|
+
ActsAsTrackable also provides methods for joining records with their associated activities,
|
|
34
|
+
making it easier to query and analyze object changes.
|
|
35
|
+
email:
|
|
36
|
+
- a.keewan@zenhr.com
|
|
37
|
+
executables: []
|
|
38
|
+
extensions: []
|
|
39
|
+
extra_rdoc_files: []
|
|
40
|
+
files:
|
|
41
|
+
- ".gitignore"
|
|
42
|
+
- ".rspec"
|
|
43
|
+
- ".ruby-version"
|
|
44
|
+
- ".travis.yml"
|
|
45
|
+
- CODE_OF_CONDUCT.md
|
|
46
|
+
- Gemfile
|
|
47
|
+
- Gemfile.lock
|
|
48
|
+
- LICENSE.txt
|
|
49
|
+
- README.md
|
|
50
|
+
- Rakefile
|
|
51
|
+
- acts_as_trackable.gemspec
|
|
52
|
+
- bin/console
|
|
53
|
+
- bin/setup
|
|
54
|
+
- lib/acts_as_trackable.rb
|
|
55
|
+
- lib/acts_as_trackable/modifier.rb
|
|
56
|
+
- lib/acts_as_trackable/trackable.rb
|
|
57
|
+
- lib/acts_as_trackable/version.rb
|
|
58
|
+
- lib/generators/acts_as_trackable/object_activity_generator.rb
|
|
59
|
+
- lib/generators/acts_as_trackable/templates/create_object_activity.rb
|
|
60
|
+
- lib/generators/acts_as_trackable/templates/object_activity.rb
|
|
61
|
+
homepage: https://www.zenhr.com
|
|
62
|
+
licenses:
|
|
63
|
+
- MIT
|
|
64
|
+
metadata:
|
|
65
|
+
homepage_uri: https://www.zenhr.com
|
|
66
|
+
source_code_uri: https://github.com/a-keewan/acts_as_trackable
|
|
67
|
+
changelog_uri: https://github.com/a-keewan/acts_as_trackable/blob/master/changelog.md
|
|
68
|
+
post_install_message:
|
|
69
|
+
rdoc_options: []
|
|
70
|
+
require_paths:
|
|
71
|
+
- lib
|
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
73
|
+
requirements:
|
|
74
|
+
- - ">="
|
|
75
|
+
- !ruby/object:Gem::Version
|
|
76
|
+
version: 2.7.2
|
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
78
|
+
requirements:
|
|
79
|
+
- - ">="
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: '0'
|
|
82
|
+
requirements: []
|
|
83
|
+
rubygems_version: 3.1.4
|
|
84
|
+
signing_key:
|
|
85
|
+
specification_version: 4
|
|
86
|
+
summary: ActsAsTrackable is a RoR gem that simplifies tracking the creation and modification
|
|
87
|
+
of database objects. It provides easy-to-use methods to make any ActiveRecord model
|
|
88
|
+
trackable and allows tracking of modifications by specific users.
|
|
89
|
+
test_files: []
|