audited_async 0.1.2 → 0.2.0

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: 101439f1aa2819b34b3d453563b01328e9b0479841ea969ea297852f51e86582
4
- data.tar.gz: 488ab1ca381c6aba19aaa0616b8b01c90aa39057b4ff08325a5d74cbd15c30b4
3
+ metadata.gz: 6149810ee92e27f07045b28bea8cf9b1ad380a36f45fdf4d94b61889d58a6969
4
+ data.tar.gz: ec08ea6bbdea4f847437c322ef94aafef077f727fe2e0cdc2f1c0a56a3258a7c
5
5
  SHA512:
6
- metadata.gz: 8b19734d353d5dedce5c35fdf1f2b65d86bca1ec57bc69c77d9078f853e308d76121e878629664caf48a4d61cdcb0cdcad20bba8a61cbfbbd911924fc391688c
7
- data.tar.gz: '08bd25f883373971610ea157d774aea2a6bdde30349df193115d1965b3816a980ea1f8bd29634e205b373fcdacb0c6cc13a20fd0112c9611ce9d4726f0560d2a'
6
+ metadata.gz: 7378037f865f092a172bdc88065bc633145684ae122a8ff64f81873b21e204cb682a60cd0914a105bf1c36ab03e085f86587cc8d34f902f0a37b5abb7156e749
7
+ data.tar.gz: c1b43a9aa415b486bb2ce1c64859a222193a6c124f68cb3a95ca1f091a313d5e0fef9d1b9bd990a8c473a7c6947f34dbe9a7b8f79582f8ec4d54d8184bdfdb1b
@@ -1,3 +1,3 @@
1
1
  inherit_gem:
2
2
  wonder-ruby-style:
3
- - presets/0.52.1.yml
3
+ - presets/latest.yml
data/Gemfile CHANGED
@@ -1,6 +1,3 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
-
5
- # Specify your gem's dependencies in audited_async.gemspec
6
3
  gemspec
@@ -1,38 +1,118 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- audited_async (0.1.2)
4
+ audited_async (0.2.0)
5
5
  audited (>= 4.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- activemodel (5.1.4)
11
- activesupport (= 5.1.4)
12
- activerecord (5.1.4)
13
- activemodel (= 5.1.4)
14
- activesupport (= 5.1.4)
15
- arel (~> 8.0)
16
- activesupport (5.1.4)
10
+ actioncable (5.2.0)
11
+ actionpack (= 5.2.0)
12
+ nio4r (~> 2.0)
13
+ websocket-driver (>= 0.6.1)
14
+ actionmailer (5.2.0)
15
+ actionpack (= 5.2.0)
16
+ actionview (= 5.2.0)
17
+ activejob (= 5.2.0)
18
+ mail (~> 2.5, >= 2.5.4)
19
+ rails-dom-testing (~> 2.0)
20
+ actionpack (5.2.0)
21
+ actionview (= 5.2.0)
22
+ activesupport (= 5.2.0)
23
+ rack (~> 2.0)
24
+ rack-test (>= 0.6.3)
25
+ rails-dom-testing (~> 2.0)
26
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
27
+ actionview (5.2.0)
28
+ activesupport (= 5.2.0)
29
+ builder (~> 3.1)
30
+ erubi (~> 1.4)
31
+ rails-dom-testing (~> 2.0)
32
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
33
+ activejob (5.2.0)
34
+ activesupport (= 5.2.0)
35
+ globalid (>= 0.3.6)
36
+ activemodel (5.2.0)
37
+ activesupport (= 5.2.0)
38
+ activerecord (5.2.0)
39
+ activemodel (= 5.2.0)
40
+ activesupport (= 5.2.0)
41
+ arel (>= 9.0)
42
+ activestorage (5.2.0)
43
+ actionpack (= 5.2.0)
44
+ activerecord (= 5.2.0)
45
+ marcel (~> 0.3.1)
46
+ activesupport (5.2.0)
17
47
  concurrent-ruby (~> 1.0, >= 1.0.2)
18
- i18n (~> 0.7)
48
+ i18n (>= 0.7, < 2)
19
49
  minitest (~> 5.1)
20
50
  tzinfo (~> 1.1)
21
- arel (8.0.0)
51
+ arel (9.0.0)
22
52
  ast (2.4.0)
23
- audited (4.6.0)
24
- activerecord (>= 4.0, < 5.2)
53
+ audited (4.7.1)
54
+ activerecord (>= 4.0, < 5.3)
55
+ builder (3.2.3)
56
+ codeclimate-test-reporter (1.0.8)
57
+ simplecov (<= 0.13)
25
58
  concurrent-ruby (1.0.5)
59
+ crass (1.0.4)
26
60
  diff-lcs (1.3)
27
- i18n (0.9.3)
61
+ docile (1.1.5)
62
+ erubi (1.7.1)
63
+ globalid (0.4.1)
64
+ activesupport (>= 4.2.0)
65
+ i18n (1.0.1)
28
66
  concurrent-ruby (~> 1.0)
67
+ json (2.1.0)
68
+ loofah (2.2.2)
69
+ crass (~> 1.0.2)
70
+ nokogiri (>= 1.5.9)
71
+ mail (2.7.0)
72
+ mini_mime (>= 0.1.1)
73
+ marcel (0.3.2)
74
+ mimemagic (~> 0.3.2)
75
+ method_source (0.9.0)
76
+ mimemagic (0.3.2)
77
+ mini_mime (1.0.0)
78
+ mini_portile2 (2.3.0)
29
79
  minitest (5.11.3)
80
+ nio4r (2.3.1)
81
+ nokogiri (1.8.2)
82
+ mini_portile2 (~> 2.3.0)
30
83
  parallel (1.12.1)
31
- parser (2.4.0.2)
32
- ast (~> 2.3)
84
+ parser (2.5.1.0)
85
+ ast (~> 2.4.0)
33
86
  powerpack (0.1.1)
87
+ rack (2.0.5)
88
+ rack-test (1.0.0)
89
+ rack (>= 1.0, < 3)
90
+ rails (5.2.0)
91
+ actioncable (= 5.2.0)
92
+ actionmailer (= 5.2.0)
93
+ actionpack (= 5.2.0)
94
+ actionview (= 5.2.0)
95
+ activejob (= 5.2.0)
96
+ activemodel (= 5.2.0)
97
+ activerecord (= 5.2.0)
98
+ activestorage (= 5.2.0)
99
+ activesupport (= 5.2.0)
100
+ bundler (>= 1.3.0)
101
+ railties (= 5.2.0)
102
+ sprockets-rails (>= 2.0.0)
103
+ rails-dom-testing (2.0.3)
104
+ activesupport (>= 4.2.0)
105
+ nokogiri (>= 1.6)
106
+ rails-html-sanitizer (1.0.4)
107
+ loofah (~> 2.2, >= 2.2.2)
108
+ railties (5.2.0)
109
+ actionpack (= 5.2.0)
110
+ activesupport (= 5.2.0)
111
+ method_source
112
+ rake (>= 0.8.7)
113
+ thor (>= 0.18.1, < 2.0)
34
114
  rainbow (3.0.0)
35
- rake (10.5.0)
115
+ rake (12.3.1)
36
116
  rspec (3.7.0)
37
117
  rspec-core (~> 3.7.0)
38
118
  rspec-expectations (~> 3.7.0)
@@ -46,21 +126,37 @@ GEM
46
126
  diff-lcs (>= 1.2.0, < 2.0)
47
127
  rspec-support (~> 3.7.0)
48
128
  rspec-support (3.7.1)
49
- rubocop (0.52.1)
129
+ rubocop (0.55.0)
50
130
  parallel (~> 1.10)
51
- parser (>= 2.4.0.2, < 3.0)
131
+ parser (>= 2.5)
52
132
  powerpack (~> 0.1)
53
133
  rainbow (>= 2.2.2, < 4.0)
54
134
  ruby-progressbar (~> 1.7)
55
135
  unicode-display_width (~> 1.0, >= 1.0.1)
56
- rubocop-rspec (1.22.2)
57
- rubocop (>= 0.52.1)
136
+ rubocop-rspec (1.25.1)
137
+ rubocop (>= 0.53.0)
58
138
  ruby-progressbar (1.9.0)
139
+ simplecov (0.13.0)
140
+ docile (~> 1.1.0)
141
+ json (>= 1.8, < 3)
142
+ simplecov-html (~> 0.10.0)
143
+ simplecov-html (0.10.2)
144
+ sprockets (3.7.1)
145
+ concurrent-ruby (~> 1.0)
146
+ rack (> 1, < 3)
147
+ sprockets-rails (3.2.1)
148
+ actionpack (>= 4.0)
149
+ activesupport (>= 4.0)
150
+ sprockets (>= 3.0.0)
151
+ thor (0.20.0)
59
152
  thread_safe (0.3.6)
60
153
  tzinfo (1.2.5)
61
154
  thread_safe (~> 0.1)
62
- unicode-display_width (1.3.0)
63
- wonder-ruby-style (0.0.6)
155
+ unicode-display_width (1.3.2)
156
+ websocket-driver (0.7.0)
157
+ websocket-extensions (>= 0.1.0)
158
+ websocket-extensions (0.1.3)
159
+ wonder-ruby-style (0.54.0)
64
160
  rubocop (~> 0.49)
65
161
  rubocop-rspec (~> 1.15)
66
162
 
@@ -69,9 +165,11 @@ PLATFORMS
69
165
 
70
166
  DEPENDENCIES
71
167
  audited_async!
72
- bundler (~> 1.16)
73
- rake (~> 10.0)
74
- rspec (~> 3.0)
168
+ bundler
169
+ codeclimate-test-reporter
170
+ rails
171
+ rake
172
+ rspec
75
173
  wonder-ruby-style
76
174
 
77
175
  BUNDLED WITH
data/README.md CHANGED
@@ -1,7 +1,11 @@
1
1
  # AuditedAsync
2
2
 
3
+ [![Maintainability](https://api.codeclimate.com/v1/badges/2d4899ab63fcea8a9144/maintainability)](https://codeclimate.com/github/leonardofalk/audited_async/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/2d4899ab63fcea8a9144/test_coverage)](https://codeclimate.com/github/leonardofalk/audited_async/test_coverage)
4
+
3
5
  AuditedAsync is an addon for audited gem which allows to create audits asynchronously using ActiveJob.
4
6
 
7
+ It's currently under initial development and I strongly recommend you do not use it in production until it reaches a stable version.
8
+
5
9
  ## Installation
6
10
 
7
11
  Add this line to your application's Gemfile, right after audited gem:
@@ -17,7 +21,69 @@ And then execute:
17
21
 
18
22
  ## Usage
19
23
 
20
- All done!
24
+ ```ruby
25
+ class Post < ApplicationRecord
26
+ audited async: true
27
+ end
28
+ ```
29
+
30
+ All done! Although you can configure some stuff, check below.
31
+
32
+ #### Enabling it programmatically
33
+
34
+ ```ruby
35
+ # config/initializers/audited_async.rb
36
+
37
+ AuditedAsync.configure do |config|
38
+ config.enabled = Rails.env.production?
39
+ end
40
+ ```
41
+
42
+ #### Changing Job execution
43
+
44
+ ```ruby
45
+ # config/initializers/audited_async.rb
46
+
47
+ AuditedAsync.configure do |config|
48
+ config.job_name = 'JobityJob'
49
+ end
50
+ ```
51
+
52
+ Create your own job:
53
+
54
+ ```ruby
55
+ class JobityJob < ApplicationJob
56
+ queue_as :audits
57
+
58
+ def perform(audit_info)
59
+ # audit_info = {
60
+ # class_name: 'Post',
61
+ # record_id: 2,
62
+ # audited_changes: "{\"json_stringified_changes\": \"with_values\"}",
63
+ # action: one of %w[create update destroy],
64
+ # comment: there will be some string here if audited comments are enabled,
65
+ # }
66
+
67
+ # ...
68
+ # run your logic
69
+ # ...
70
+
71
+ # job must have this line at the end
72
+ class_name.constantize.send(:write_audit, attributes)
73
+ # attributes = {
74
+ # audited_changes: {hash_changes: :with_values},
75
+ # action: one of %w[create update destroy],
76
+ # comment: comment, if enabled
77
+ # }
78
+ end
79
+ end
80
+ ```
81
+
82
+ To see how the default job performs, [look here](./lib/audited_async/audit_async_job).
83
+
84
+ ## How It Works
85
+
86
+ AuditedAsync safely inject the `async` option into audited model option using functional programming. If enabled, it'll move audit creation logic into an ActiveJob instance, then it's sent to the queue to be executed later.
21
87
 
22
88
  ## Development
23
89
 
@@ -27,7 +93,11 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
27
93
 
28
94
  ## Contributing
29
95
 
30
- Bug reports and pull requests are welcome on GitHub at https://github.com/leonardofalk/audited_async. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
96
+ Bug reports and pull requests are welcome on GitHub at <https://github.com/leonardofalk/audited_async>. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
97
+
98
+ ## To Do
99
+
100
+ - [ ] Elaborate more test cases.
31
101
 
32
102
  ## License
33
103
 
@@ -1,15 +1,15 @@
1
1
 
2
- lib = File.expand_path("../lib", __FILE__)
2
+ lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'audited_async/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'audited_async'
8
8
  spec.version = AuditedAsync::VERSION
9
- spec.authors = [ 'Leonardo Falk' ]
10
- spec.email = %w[ leonardo.falk@hotmail.com ]
9
+ spec.authors = ['Leonardo Falk']
10
+ spec.email = %w[leonardo.falk@hotmail.com]
11
11
 
12
- spec.summary = %q{ Execute audited asynchronously. }
12
+ spec.summary = 'Execute audited asynchronously with ActiveJob.'
13
13
  spec.description = spec.summary
14
14
  spec.homepage = 'https://github.com/leonardofalk/audited_async'
15
15
  spec.license = 'MIT'
@@ -18,14 +18,16 @@ Gem::Specification.new do |spec|
18
18
  f.match(%r{^(test|spec|features)/})
19
19
  end
20
20
 
21
- spec.bindir = 'exe'
21
+ spec.bindir = 'bin'
22
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
- spec.require_paths = %w[ lib ]
23
+ spec.require_paths = %w[lib]
24
24
 
25
25
  spec.add_dependency 'audited', '>= 4.0'
26
26
 
27
- spec.add_development_dependency 'bundler', '~> 1.16'
28
- spec.add_development_dependency 'rake', '~> 10.0'
29
- spec.add_development_dependency 'rspec', '~> 3.0'
27
+ spec.add_development_dependency 'bundler'
28
+ spec.add_development_dependency 'rake'
29
+ spec.add_development_dependency 'rspec'
30
30
  spec.add_development_dependency 'wonder-ruby-style'
31
+ spec.add_development_dependency 'rails'
32
+ spec.add_development_dependency 'codeclimate-test-reporter'
31
33
  end
@@ -1,27 +1,70 @@
1
- require 'active_support'
1
+ require 'audited'
2
2
  require 'audited_async/version'
3
+ require 'audited_async/configurator'
3
4
  require 'audited_async/audit_async_job'
4
5
 
6
+ module AuditedAsync
7
+ class << self
8
+ def configure
9
+ @configurator ||= AuditedAsync::Configurator.new
10
+
11
+ yield @configurator
12
+ end
13
+
14
+ def config
15
+ @configurator
16
+ end
17
+ end
18
+ end
19
+
20
+ module Audited::Auditor::ClassMethods
21
+ attr_reader :audited_async_enabled
22
+
23
+ _audited = instance_method :audited
24
+
25
+ define_method :audited do |options = {}|
26
+ @audited_async_enabled = options.fetch(:async, false) && AuditedAsync.config.enabled?
27
+
28
+ _audited.bind(self).(options)
29
+ end
30
+
31
+ alias audited_async_enabled? audited_async_enabled
32
+ end
33
+
5
34
  module Audited::Auditor::AuditedInstanceMethods
6
- def audit_create
35
+ _audit_create = instance_method :audit_create
36
+ _audit_update = instance_method :audit_update
37
+ _audit_destroy = instance_method :audit_destroy
38
+
39
+ def audited_async_enabled?
40
+ self.class.audited_async_enabled?
41
+ end
42
+
43
+ define_method :audit_create do
44
+ return _audit_create.bind(self).() unless audited_async_enabled?
45
+
7
46
  perform_async_audit 'create'
8
47
  end
9
48
 
10
- def audit_update
49
+ define_method :audit_update do
50
+ return _audit_update.bind(self).() unless audited_async_enabled?
51
+
11
52
  unless (changes = audited_changes).empty? && audit_comment.blank?
12
53
  perform_async_audit 'update'
13
54
  end
14
55
  end
15
56
 
16
- def audit_destroy
57
+ define_method :audit_destroy do
58
+ return _audit_destroy.bind(self).() unless audited_async_enabled?
59
+
17
60
  perform_async_audit 'destroy' unless new_record?
18
61
  end
19
62
 
20
63
  def perform_async_audit(method)
21
- AuditedAsync::AuditAsyncJob.perform_later class_name: self.class.name,
22
- record_id: send(self.class.primary_key.to_sym),
23
- action: method,
24
- audited_changes: audited_attributes.to_json,
25
- comment: audit_comment
64
+ AuditedAsync.config.job.perform_later class_name: self.class.name,
65
+ record_id: send(self.class.primary_key.to_sym),
66
+ action: method,
67
+ audited_changes: audited_attributes.to_json,
68
+ comment: audit_comment
26
69
  end
27
70
  end
@@ -0,0 +1,16 @@
1
+ module AuditedAsync
2
+ class Configurator
3
+ attr_accessor :enabled, :job_name
4
+
5
+ def initialize
6
+ @enabled = true
7
+ @job_name = 'AuditedAsync::AuditAsyncJob'
8
+ end
9
+
10
+ alias enabled? enabled
11
+
12
+ def job
13
+ @job_name.constantize
14
+ end
15
+ end
16
+ end
@@ -1,3 +1,3 @@
1
1
  module AuditedAsync
2
- VERSION = '0.1.2'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: audited_async
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leonardo Falk
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-05 00:00:00.000000000 Z
11
+ date: 2018-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: audited
@@ -28,44 +28,44 @@ dependencies:
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '1.16'
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '1.16'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '10.0'
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '10.0'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '3.0'
61
+ version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '3.0'
68
+ version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: wonder-ruby-style
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -80,7 +80,35 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
- description: Execute audited asynchronously.
83
+ - !ruby/object:Gem::Dependency
84
+ name: rails
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: codeclimate-test-reporter
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Execute audited asynchronously with ActiveJob.
84
112
  email:
85
113
  - leonardo.falk@hotmail.com
86
114
  executables: []
@@ -101,6 +129,7 @@ files:
101
129
  - bin/setup
102
130
  - lib/audited_async.rb
103
131
  - lib/audited_async/audit_async_job.rb
132
+ - lib/audited_async/configurator.rb
104
133
  - lib/audited_async/version.rb
105
134
  homepage: https://github.com/leonardofalk/audited_async
106
135
  licenses:
@@ -122,8 +151,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
151
  version: '0'
123
152
  requirements: []
124
153
  rubyforge_project:
125
- rubygems_version: 2.7.4
154
+ rubygems_version: 2.7.6
126
155
  signing_key:
127
156
  specification_version: 4
128
- summary: Execute audited asynchronously.
157
+ summary: Execute audited asynchronously with ActiveJob.
129
158
  test_files: []