audit_tracker 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/.rubocop.yml +2 -0
- data/.standard.yml +3 -0
- data/Gemfile +17 -0
- data/LICENSE.txt +21 -0
- data/Rakefile +11 -0
- data/audit_tracker.gemspec +38 -0
- data/config.ru +9 -0
- data/doc/dependency_decisions.yml +3 -0
- data/docs/CHANGELOG.md +5 -0
- data/docs/README.md +128 -0
- data/lib/audit_tracker/dsl.rb +51 -0
- data/lib/audit_tracker/model_helper.rb +41 -0
- data/lib/audit_tracker/railtie.rb +15 -0
- data/lib/audit_tracker/tracker.rb +97 -0
- data/lib/audit_tracker/version.rb +5 -0
- data/lib/audit_tracker.rb +92 -0
- data/mkdocs.yml +6 -0
- data/sig/audit_tracker.rbs +4 -0
- metadata +137 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4b9079e64cb35e5229690f0ea50e4464767249e8b6154af79035ba584b3caf1a
|
4
|
+
data.tar.gz: 42206ff6944bdc9770a73ee1692e3f508b586c9f65fc19d408a592ed0c39329e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dc762930e22fb6036963eae309ed6d08bf0a3c25ac4bca21b8913b23e322c93b3f68c5e9338887a5165b0d38c22c5c44a4b6267e45da475048f9c837bfe7ab59
|
7
|
+
data.tar.gz: c225767c844fc9c5025352ec4fe14b774cf6580bb74708a85241fb613236a7855a4f2e2f18d481c5f4341514d10719bfd082a15f5828a07a7d11a7fa974b6a0a
|
data/.rubocop.yml
ADDED
data/.standard.yml
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in audit_tracker.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
rails_version = ENV.fetch("RAILS_VERSION", ">= 5.2.8.1")
|
9
|
+
|
10
|
+
gem "rails", rails_version
|
11
|
+
|
12
|
+
gem "byebug"
|
13
|
+
gem "license_finder", ">= 7.0"
|
14
|
+
gem "rake", ">= 13.0"
|
15
|
+
gem "rspec", ">= 3.0"
|
16
|
+
gem "rubocop", ">= 1.32"
|
17
|
+
gem "rubocop-powerhome", ">= 0.5.0"
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2022 Power Home Remodeling
|
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/Rakefile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/audit_tracker/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "audit_tracker"
|
7
|
+
spec.version = AuditTracker::VERSION
|
8
|
+
spec.authors = ["Carlos Palhares"]
|
9
|
+
spec.email = ["chjunior@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "AuditTracker helps you centralize data tracking configuration to be used across different models"
|
12
|
+
spec.description = spec.summary
|
13
|
+
spec.homepage = "https://github.com/powerhome/power-tools"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = ">= 2.7"
|
16
|
+
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
19
|
+
spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/main/packages/audit_tracker/docs/CHANGELOG.md"
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
+
spec.files = Dir.chdir(__dir__) do
|
24
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
25
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
26
|
+
end
|
27
|
+
end
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
32
|
+
spec.add_development_dependency "activerecord", ">= 5.2.8.1"
|
33
|
+
spec.add_development_dependency "combustion", "~> 1.3"
|
34
|
+
spec.add_development_dependency "rspec-rails", "~> 5.1.2"
|
35
|
+
spec.add_development_dependency "shoulda-matchers", "~> 5.1.0"
|
36
|
+
spec.add_development_dependency "sqlite3", "~> 1.4.2"
|
37
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
38
|
+
end
|
data/config.ru
ADDED
data/docs/CHANGELOG.md
ADDED
data/docs/README.md
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
# AuditTracker
|
2
|
+
|
3
|
+
AuditTracker helps you centralize data tracking configuration to be used across different models.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Install the gem and add it to the application's Gemfile by executing:
|
8
|
+
|
9
|
+
$ bundle add audit_tracker
|
10
|
+
|
11
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
12
|
+
|
13
|
+
$ gem install audit_tracker
|
14
|
+
|
15
|
+
## Usage Example
|
16
|
+
|
17
|
+
In this example, we'll track the actors that created or updated different models, like the user, title, and their department at the time. This is represented like this in AuditTracker:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
AuditTracker.setup do
|
21
|
+
tracker :user do
|
22
|
+
value { ::Internal::Current.user }
|
23
|
+
create :created_by, foreign_key: :created_by_id, class_name: "::Internal::User"
|
24
|
+
update :updated_by, foreign_key: :updated_by_id, class_name: "::Internal::User"
|
25
|
+
end
|
26
|
+
tracker :user_department do
|
27
|
+
value { ::Internal::Current.user&.department }
|
28
|
+
create :created_by_department, foreign_key: :created_by_department_id, class_name: "::Internal::Department"
|
29
|
+
update :updated_by_department, foreign_key: :updated_by_department_id, class_name: "::Internal::Department"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
```
|
33
|
+
|
34
|
+
Then, enable the trackers on each model:
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
class Lead < ApplicationRecord
|
38
|
+
track_audit_data user: true, user_department: true
|
39
|
+
end
|
40
|
+
```
|
41
|
+
|
42
|
+
This will create each relation setup by the tracker:
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
lead.created_by => User
|
46
|
+
lead.created_by_department => Department
|
47
|
+
lead.updated_by => User
|
48
|
+
lead.updated_by_department => Department
|
49
|
+
```
|
50
|
+
|
51
|
+
When a relation is disabled, the tracker is not setup:
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
module Internal
|
55
|
+
class Home < ::Internal::ApplicationRecord
|
56
|
+
track_audit_data user: true
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
home.created_by => User
|
61
|
+
home.created_by_department => NoMethodError
|
62
|
+
home.updated_by => User
|
63
|
+
home.updated_by_department => NoMethodError
|
64
|
+
```
|
65
|
+
|
66
|
+
### Disabling individual relations
|
67
|
+
|
68
|
+
To enable each relation, AuditTracker will first check if the column exists (`foreign_key`). If it doesn't exist, the relation won't be created, and the tracker won't be enabled for it.
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
module Internal
|
72
|
+
class Sale < ::Internal::ApplicationRecord
|
73
|
+
track_audit_data user: true
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
Sale.column_names => ["id", "price", "updated_by_id"]
|
78
|
+
sale.created_by => User
|
79
|
+
sale.created_by_department => NoMethodError
|
80
|
+
sale.updated_by => NoMethodError
|
81
|
+
sale.updated_by_department => NoMethodError
|
82
|
+
```
|
83
|
+
|
84
|
+
### Overriding relation options
|
85
|
+
|
86
|
+
To override a relation option in a tracker, use the tracker options:
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
|
90
|
+
module Internal
|
91
|
+
class Score < ::Internal::ApplicationRecord
|
92
|
+
track_audit_data(
|
93
|
+
user: {
|
94
|
+
created_by: {
|
95
|
+
class_name: "::Internal::ManagerUser",
|
96
|
+
value: -> { ::Internal::Current.user.becomes(::Internal::ManagerUser) },
|
97
|
+
},
|
98
|
+
updated_by: {
|
99
|
+
class_name: "::Internal::ManagerUser",
|
100
|
+
value: -> { ::Internal::Current.user.becomes(::Internal::ManagerUser) },
|
101
|
+
},
|
102
|
+
}
|
103
|
+
)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
score.created_by => ManagerUser
|
108
|
+
score.updated_by => ManagerUser
|
109
|
+
```
|
110
|
+
|
111
|
+
## Internal Example
|
112
|
+
|
113
|
+
The above example lives in our [specs](specs/internal).
|
114
|
+
|
115
|
+
|
116
|
+
## Development
|
117
|
+
|
118
|
+
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.
|
119
|
+
|
120
|
+
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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
121
|
+
|
122
|
+
## Contributing
|
123
|
+
|
124
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/powerhome/power-tools.
|
125
|
+
|
126
|
+
## License
|
127
|
+
|
128
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AuditTracker
|
4
|
+
# AuditTracker DSL modules
|
5
|
+
module DSL
|
6
|
+
def self.build(&block)
|
7
|
+
Setup.module_eval(&block)
|
8
|
+
end
|
9
|
+
|
10
|
+
# AuditTracker::DSL::Setup is the DSL cotext of the block in AuditTracker.setup
|
11
|
+
#
|
12
|
+
module Setup
|
13
|
+
module_function
|
14
|
+
|
15
|
+
def tracker(key, &block)
|
16
|
+
::AuditTracker.trackers[key] = Tracking.build(&block)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# AuditTracker::DSL::Setup is the DSL cotext of the block in `DSL::Setup.tracker`
|
21
|
+
#
|
22
|
+
class Tracking
|
23
|
+
def self.build(&block)
|
24
|
+
tracker = new
|
25
|
+
tracker.instance_eval(&block)
|
26
|
+
tracker.tracker
|
27
|
+
end
|
28
|
+
|
29
|
+
def tracker
|
30
|
+
::AuditTracker::Tracker.new(on: @on, value: @value)
|
31
|
+
end
|
32
|
+
|
33
|
+
def on(event, relation, **options)
|
34
|
+
@on ||= []
|
35
|
+
@on << [event, relation, options]
|
36
|
+
end
|
37
|
+
|
38
|
+
def update(relation, **options)
|
39
|
+
on(:save, relation, **options)
|
40
|
+
end
|
41
|
+
|
42
|
+
def create(relation, **options)
|
43
|
+
on(:create, relation, **options)
|
44
|
+
end
|
45
|
+
|
46
|
+
def value(&block)
|
47
|
+
@value = block
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AuditTracker
|
4
|
+
# Model helper for setting up trackers in an ActiveRecord model
|
5
|
+
#
|
6
|
+
module ModelHelper
|
7
|
+
#
|
8
|
+
# Helper to apply AuditTracker to a model. This helper is automatically added
|
9
|
+
# to ActiveRecord::Base when it loads (@see {AuditTracker::Railtie})
|
10
|
+
#
|
11
|
+
# `track_audit_data` options are the keys of the trackers defined. Each tracker is
|
12
|
+
# enabled by passing `true` to it's key.
|
13
|
+
#
|
14
|
+
# I.e.:
|
15
|
+
#
|
16
|
+
# track_audit_data user: true, user_department: true
|
17
|
+
#
|
18
|
+
# A hash of options can also be used to override any tracker option:
|
19
|
+
#
|
20
|
+
# track_audit_data(
|
21
|
+
# user: {
|
22
|
+
# created_by: { class_name: "::ManagerUser" },
|
23
|
+
# updated_by: { class_name: "::ManagerUser" },
|
24
|
+
# }
|
25
|
+
# )
|
26
|
+
#
|
27
|
+
# And the value block can also be overriden:
|
28
|
+
#
|
29
|
+
# track_audit_data(
|
30
|
+
# user: {
|
31
|
+
# created_by: { class_name: "::ManagerUser", value: -> { User.current.becomes(ManagerUser) } },
|
32
|
+
# updated_by: { class_name: "::ManagerUser", value: -> { User.current.becomes(ManagerUser) } },
|
33
|
+
# }
|
34
|
+
# )
|
35
|
+
#
|
36
|
+
# @param options [Hash<Symbol,(Hash, Boolean)>] options hash
|
37
|
+
def track_audit_data(**options)
|
38
|
+
::AuditTracker.apply(self, **options)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AuditTracker
|
4
|
+
# Auto injects the ::AuditTracker::ModelHelper into ActiveRecord classes
|
5
|
+
#
|
6
|
+
class Railtie < Rails::Railtie
|
7
|
+
railtie_name :audit_tracker
|
8
|
+
|
9
|
+
initializer "audit_tracker.initialize_model_helper" do
|
10
|
+
ActiveSupport.on_load(:active_record) do
|
11
|
+
extend ::AuditTracker::ModelHelper
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AuditTracker
|
4
|
+
#
|
5
|
+
# ::AuditTracker::Tracker represents the tracker and is responsible
|
6
|
+
# for setting up the models to be tracked
|
7
|
+
#
|
8
|
+
# I.e.:
|
9
|
+
#
|
10
|
+
# tracker = Tracker.new(
|
11
|
+
# create: [:created_by, class_name: "User", foreign_key: "created_by_id"]),
|
12
|
+
# update: [:updated_by, class_name: "User", foreign_key: "updated_by_id"]),
|
13
|
+
# value: -> { User.current }
|
14
|
+
# )
|
15
|
+
# tracker.apply(MyTrackedModel)
|
16
|
+
#
|
17
|
+
# After applying, if MyTrackedModel represents a table that contains the
|
18
|
+
# necessary foreign keys, the relationships (`created_by` and `updated_by`)
|
19
|
+
# and callbacks (before create / update) will be added to it.
|
20
|
+
#
|
21
|
+
# ::AuditTracker::Tracker is the core of AuditTracker, and a collection of trackers
|
22
|
+
# is built into AuditTracker.trackers via AuditTracker.setup.
|
23
|
+
#
|
24
|
+
class Tracker
|
25
|
+
def initialize(on:, value:)
|
26
|
+
@on = on
|
27
|
+
@value = value
|
28
|
+
|
29
|
+
super()
|
30
|
+
end
|
31
|
+
|
32
|
+
def apply(model, overrides)
|
33
|
+
@on.each do |event, relation, options|
|
34
|
+
options = options.merge(overrides[relation] || {})
|
35
|
+
apply_relation(model, relation, options, event)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def apply_relation(model, relation, options, event)
|
42
|
+
return unless table_exists?(model)
|
43
|
+
return unless foreign_key_exist?(model, relation, **options)
|
44
|
+
|
45
|
+
value = options.delete(:value) || @value
|
46
|
+
|
47
|
+
model.belongs_to(relation, **options) unless relation_exist?(model, relation)
|
48
|
+
model.set_callback event, :before, Callback.new(value, relation, event)
|
49
|
+
end
|
50
|
+
|
51
|
+
def relation_exist?(model, relation)
|
52
|
+
model.reflect_on_association(relation).present?
|
53
|
+
end
|
54
|
+
|
55
|
+
def foreign_key_exist?(model, relation, foreign_key: nil, **)
|
56
|
+
raise ArgumentError, "foreign_key is not set for #{relation}" unless foreign_key
|
57
|
+
|
58
|
+
model.column_names.include?(foreign_key.to_s)
|
59
|
+
end
|
60
|
+
|
61
|
+
def table_exists?(model)
|
62
|
+
model.table_exists?
|
63
|
+
rescue
|
64
|
+
false
|
65
|
+
end
|
66
|
+
|
67
|
+
# :nodoc:
|
68
|
+
class Callback
|
69
|
+
def initialize(value_fn, relation, event)
|
70
|
+
@value = value_fn
|
71
|
+
@relation = relation
|
72
|
+
@event = event
|
73
|
+
end
|
74
|
+
|
75
|
+
def respond_to_missing?(method)
|
76
|
+
method.to_s.eql?("before_#{@event}")
|
77
|
+
end
|
78
|
+
|
79
|
+
def method_missing(method, ...)
|
80
|
+
if respond_to_missing?(method)
|
81
|
+
call(...)
|
82
|
+
else
|
83
|
+
super
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
|
89
|
+
def call(record)
|
90
|
+
association = record.association(@relation)
|
91
|
+
return if record.attribute_changed?(association.reflection.foreign_key)
|
92
|
+
|
93
|
+
association.writer(@value.call(record))
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "audit_tracker/dsl"
|
4
|
+
require_relative "audit_tracker/model_helper"
|
5
|
+
require_relative "audit_tracker/railtie" if defined?(Rails)
|
6
|
+
require_relative "audit_tracker/tracker"
|
7
|
+
require_relative "audit_tracker/version"
|
8
|
+
|
9
|
+
# AuditTracker helps you centralize data tracking configuration to be used accross
|
10
|
+
# different models
|
11
|
+
module AuditTracker
|
12
|
+
# Trackers setup in AuditTracker
|
13
|
+
#
|
14
|
+
# @return [Hash<Symbol,::AuditTracker::Tracker>]
|
15
|
+
#
|
16
|
+
def self.trackers
|
17
|
+
@trackers ||= {}
|
18
|
+
end
|
19
|
+
|
20
|
+
# Setup `AuditTracker::Tracker`'s
|
21
|
+
#
|
22
|
+
# setup entry point for data trackers. Multiple calls to this method are cumulative,
|
23
|
+
# and trackers with the same key override each other depending on load order.
|
24
|
+
#
|
25
|
+
# I.e.:
|
26
|
+
#
|
27
|
+
# AuditTracker.setup do
|
28
|
+
# tracker :user do
|
29
|
+
# value { ::Internal::Current.user }
|
30
|
+
# create :created_by, foreign_key: :created_by_id, class_name: "::Internal::User"
|
31
|
+
# update :updated_by, foreign_key: :updated_by_id, class_name: "::Internal::User"
|
32
|
+
# end
|
33
|
+
# tracker :user_department do
|
34
|
+
# value { ::Internal::Current.user&.department }
|
35
|
+
# create(
|
36
|
+
# :created_by_department,
|
37
|
+
# foreign_key: :created_by_department_id,
|
38
|
+
# class_name: "::Internal::Department"
|
39
|
+
# )
|
40
|
+
# update(
|
41
|
+
# :updated_by_department,
|
42
|
+
# foreign_key: :updated_by_department_id,
|
43
|
+
# class_name: "::Internal::Department"
|
44
|
+
# )
|
45
|
+
# end
|
46
|
+
# end
|
47
|
+
#
|
48
|
+
# Trackers will track a specific value, so the `value`` is always required to be defined.
|
49
|
+
# Each line after that define a different event. `create` and `update` are helper methods
|
50
|
+
# to create events.
|
51
|
+
#
|
52
|
+
# `update` is tied to the `:save` event of activerecord. That means that the value will be
|
53
|
+
# tracked before create and before update.
|
54
|
+
#
|
55
|
+
# Each event defined will generate an active record relation, and will update that relation
|
56
|
+
# before the event (i.e.: `before_update`, `before_create`).
|
57
|
+
#
|
58
|
+
def self.setup(&block)
|
59
|
+
::AuditTracker::DSL.build(&block)
|
60
|
+
end
|
61
|
+
|
62
|
+
# Enables the given trackers in the given model
|
63
|
+
#
|
64
|
+
# I.e.:
|
65
|
+
#
|
66
|
+
# The following would create two trackers (user and user_department), but only apply the
|
67
|
+
# former to Lead:
|
68
|
+
#
|
69
|
+
# AuditTracker.setup do
|
70
|
+
# tracker(:user) do
|
71
|
+
# update :updated_by, foreign_key: "updated_by_id", class_name: "::User"
|
72
|
+
# value { User.current }
|
73
|
+
# end
|
74
|
+
# tracker(:user_department) do
|
75
|
+
# update :updated_by_department, foreign_key: "updated_by_department_id", class_name: "::Department"
|
76
|
+
# value { User.current&.department }
|
77
|
+
# end
|
78
|
+
# end
|
79
|
+
#
|
80
|
+
# AuditTracker.apply(::Lead, user: true)
|
81
|
+
#
|
82
|
+
# @param model [ActiveRecord::Base] any activerecord model
|
83
|
+
# @param options [Hash<Symbol,(Hash,Boolean)>] tracking options
|
84
|
+
# @see ::AuditTracker::ModelHelper
|
85
|
+
def self.apply(model, options)
|
86
|
+
@trackers.each do |key, tracker|
|
87
|
+
next unless options[key]
|
88
|
+
|
89
|
+
tracker.apply(model, options[key] == true ? {} : options[key])
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
data/mkdocs.yml
ADDED
metadata
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: audit_tracker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Carlos Palhares
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-07-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 5.2.8.1
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 5.2.8.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: combustion
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec-rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 5.1.2
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 5.1.2
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: shoulda-matchers
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 5.1.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 5.1.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: sqlite3
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.4.2
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.4.2
|
83
|
+
description: AuditTracker helps you centralize data tracking configuration to be used
|
84
|
+
across different models
|
85
|
+
email:
|
86
|
+
- chjunior@gmail.com
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".rubocop.yml"
|
92
|
+
- ".standard.yml"
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE.txt
|
95
|
+
- Rakefile
|
96
|
+
- audit_tracker.gemspec
|
97
|
+
- config.ru
|
98
|
+
- doc/dependency_decisions.yml
|
99
|
+
- docs/CHANGELOG.md
|
100
|
+
- docs/README.md
|
101
|
+
- lib/audit_tracker.rb
|
102
|
+
- lib/audit_tracker/dsl.rb
|
103
|
+
- lib/audit_tracker/model_helper.rb
|
104
|
+
- lib/audit_tracker/railtie.rb
|
105
|
+
- lib/audit_tracker/tracker.rb
|
106
|
+
- lib/audit_tracker/version.rb
|
107
|
+
- mkdocs.yml
|
108
|
+
- sig/audit_tracker.rbs
|
109
|
+
homepage: https://github.com/powerhome/power-tools
|
110
|
+
licenses:
|
111
|
+
- MIT
|
112
|
+
metadata:
|
113
|
+
homepage_uri: https://github.com/powerhome/power-tools
|
114
|
+
source_code_uri: https://github.com/powerhome/power-tools
|
115
|
+
changelog_uri: https://github.com/powerhome/power-tools/blob/main/packages/audit_tracker/docs/CHANGELOG.md
|
116
|
+
rubygems_mfa_required: 'true'
|
117
|
+
post_install_message:
|
118
|
+
rdoc_options: []
|
119
|
+
require_paths:
|
120
|
+
- lib
|
121
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '2.7'
|
126
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
requirements: []
|
132
|
+
rubygems_version: 3.3.7
|
133
|
+
signing_key:
|
134
|
+
specification_version: 4
|
135
|
+
summary: AuditTracker helps you centralize data tracking configuration to be used
|
136
|
+
across different models
|
137
|
+
test_files: []
|