audit_loggable 1.0.0 → 1.1.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: 2e4abe618e6c92a3ffe1c0bb77bd209f6daada37a371a4e82f251c403460c7ac
4
- data.tar.gz: bce5504334ae400bc74c6b30ba841bd1cfc415797430bd1636c791a2f15bfdcd
3
+ metadata.gz: ec0a5517dd3f92ad8be7051785176487c7e7fdec36762421469224bf9461eaaf
4
+ data.tar.gz: fd8d3fd6157d0b74b74df9d73d6ee8cf55fbb3be30c717b8ac2264ff5b959970
5
5
  SHA512:
6
- metadata.gz: a981ea5a538ed5ace3ce70bec24a0d9c2a664b8fcc00d92ec0adf0386bd06df43677d414af3ca9c0ed344d04339ccdd872940bb2d8afe4f10be833fb32335b1a
7
- data.tar.gz: e614a8b7208a4ddaac957b1362fbd63c4ee2ff1a0402c8edf6810a4266c49ef9da1ccd7eb63225e6aa729b9ab612027cf6996db769356eb148075808354d2c01
6
+ metadata.gz: dd8ff1bcf4cfb1ea6a80d7992f13c7bc387bbf43de128b32bf6f97e35e424ad24646828648a2aacc9699db519b14d289a577cc5cce724e7a12b81860d668b60e
7
+ data.tar.gz: 3122c66ac200a2cc7d4720516596d6f4a81d3ff855f6503119cf2ad26da11c29ee8e8984a3eb508a9bfd547291afaf19c0c9b03d8c450bed16f6674ab1c2c7a5
@@ -14,18 +14,13 @@ jobs:
14
14
  runs-on: ubuntu-latest
15
15
  strategy:
16
16
  matrix:
17
- ruby: ['2.5', '2.6', '2.7', '3.0']
18
- activerecord: ['6.0', '6.1']
17
+ ruby: ['2.7', '3.0', '3.1']
18
+ activerecord: ['6.0', '6.1', '7.0']
19
19
  experimental: [false]
20
20
  exclude:
21
- - ruby: '3.0'
21
+ - ruby: '3.1'
22
22
  activerecord: '6.0'
23
23
  experimental: false
24
- include:
25
- # waiting for a release of https://github.com/rails/rails/pull/39697
26
- - ruby: '3.0'
27
- activerecord: '6.0'
28
- experimental: true
29
24
  continue-on-error: ${{ matrix.experimental }}
30
25
  env:
31
26
  APPRAISAL: rails_${{ matrix.activerecord }}
@@ -40,4 +35,6 @@ jobs:
40
35
  bundle install
41
36
  bundle exec appraisal $APPRAISAL bundle install
42
37
  - name: Run tests
38
+ env:
39
+ TZ: "Asia/Tokyo"
43
40
  run: bundle exec appraisal $APPRAISAL rake
data/Appraisals CHANGED
@@ -7,3 +7,7 @@ end
7
7
  appraise "rails_6.1" do
8
8
  gem "rails", "~> 6.1.0"
9
9
  end
10
+
11
+ appraise "rails_7.0" do
12
+ gem "rails", "~> 7.0.1"
13
+ end
data/CHANGELOG.md CHANGED
@@ -1,6 +1,21 @@
1
1
  ## Unreleased
2
2
 
3
3
 
4
+ ## 1.1.0 (2022-09-23)
5
+
6
+ ### Changes
7
+
8
+ * Make configurable timezone of timestamp
9
+ * Change `AuditRecord#as_json` to accept the options of `Hash#as_json`
10
+
11
+ ### Misc
12
+
13
+ * CI against for Rails 7.0
14
+ * CI against for Ruby 3.1
15
+ * Require MFA to release gem
16
+ * Drop support for Ruby 2.5/2.6
17
+
18
+
4
19
  ## 1.0.0 (2021-03-30)
5
20
 
6
21
  * Initial release
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # AuditLoggable
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/audit_loggable.svg)](https://badge.fury.io/rb/audit_loggable)
3
4
  [![Build](https://github.com/vividgarden/audit_loggable/actions/workflows/ruby.yml/badge.svg)](https://github.com/vividgarden/audit_loggable/actions/workflows/ruby.yml)
4
5
 
5
6
  AuditLoggable is a Rails plugin gem that logs changes to your models. AuditLoggable can also record who made those changes.
@@ -43,6 +44,7 @@ Options
43
44
  | `audit_log_shift_age` | Integer or String | Same as `shift_age` option of `Logger` class of stdlib. | `0` |
44
45
  | `audit_log_shift_size` | Integer | Same as `shift_size` option of `Logger` class of stdlib. | `1048576` |
45
46
  | `audit_log_shift_period_suffix` | String | Same as `shift_period_suffix` options of `Logger` class of stdlib. | `%Y%m%d` |
47
+ | `audit_log_timezone` | Enum | The timezone of timestamp. Any value of `:local` or `:utc`. | `local` |
46
48
 
47
49
  ### Extend your model by `AuditLoggable::Extension`
48
50
  ``` ruby
@@ -23,6 +23,8 @@ Gem::Specification.new do |spec|
23
23
  spec.metadata["homepage_uri"] = spec.homepage
24
24
  spec.metadata["source_code_uri"] = spec.homepage
25
25
  spec.metadata["changelog_uri"] = "https://github.com/vividgarden/audit_loggable/blob/main/CHANGELOG.md"
26
+
27
+ spec.metadata["rubygems_mfa_required"] = "true"
26
28
  else
27
29
  raise "RubyGems 2.0 or newer is required to protect against " \
28
30
  "public gem pushes."
@@ -37,7 +39,7 @@ Gem::Specification.new do |spec|
37
39
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
38
40
  spec.require_paths = ["lib"]
39
41
 
40
- spec.required_ruby_version = ">= 2.5"
42
+ spec.required_ruby_version = ">= 2.7"
41
43
 
42
44
  spec.add_dependency "activerecord", ">= 6.0"
43
45
  spec.add_dependency "activesupport", ">= 6.0"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 7.0.1"
6
+
7
+ gemspec path: "../"
@@ -11,7 +11,7 @@ module AuditLoggable
11
11
  @request_uuid = request_uuid
12
12
  end
13
13
 
14
- def as_json(*)
14
+ def as_json(options = nil)
15
15
  {
16
16
  auditable: { id: auditable.id, type: auditable.class.polymorphic_name },
17
17
  user: user ? { id: user.id, type: user.class.polymorphic_name } : nil,
@@ -19,7 +19,7 @@ module AuditLoggable
19
19
  changes: changeset.to_json, # serialize to JSON string
20
20
  remote_address: remote_address,
21
21
  request_uuid: request_uuid
22
- }
22
+ }.as_json(options)
23
23
  end
24
24
 
25
25
  private
@@ -3,13 +3,14 @@
3
3
  module AuditLoggable
4
4
  class Configuration
5
5
  attr_accessor :audit_log_path, :audit_log_shift_age, :audit_log_shift_size, :audit_log_shift_period_suffix,
6
- :auditing_enabled
6
+ :auditing_enabled, :audit_log_timezone
7
7
 
8
8
  def initialize
9
9
  self.auditing_enabled = true
10
10
  self.audit_log_shift_age = 0
11
11
  self.audit_log_shift_size = 1024 * 1024
12
12
  self.audit_log_shift_period_suffix = "%Y%m%d"
13
+ self.audit_log_timezone = :local
13
14
  end
14
15
  end
15
16
  end
@@ -5,8 +5,22 @@ require "logger"
5
5
  module AuditLoggable
6
6
  class Logger
7
7
  class JSONFormatter < ::Logger::Formatter
8
+ attr_reader :timezone
9
+
10
+ def initialize(timezone:)
11
+ raise ArgumentError unless %i[utc local].include? timezone
12
+
13
+ @timezone = timezone
14
+ end
15
+
8
16
  def call(_severity, time, _progname, message)
9
- h = { timestamp: time, record: message }
17
+ timestamp =
18
+ case timezone
19
+ when :utc then time.getutc
20
+ when :local then time.getlocal
21
+ end
22
+
23
+ h = { timestamp: timestamp, record: message }
10
24
  "#{h.to_json}\n"
11
25
  end
12
26
  end
@@ -20,8 +34,8 @@ module AuditLoggable
20
34
  end
21
35
 
22
36
  class InternalLogger < ::Logger
23
- def initialize(logdev, shift_age:, shift_size:, shift_period_suffix:)
24
- super(nil, level: :info, formatter: JSONFormatter.new)
37
+ def initialize(logdev, shift_age:, shift_size:, shift_period_suffix:, timezone:)
38
+ super(nil, level: :info, formatter: JSONFormatter.new(timezone: timezone))
25
39
 
26
40
  return unless logdev
27
41
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AuditLoggable
4
- VERSION = "1.0.0"
4
+ VERSION = "1.1.0"
5
5
  end
@@ -21,7 +21,7 @@ module AuditLoggable
21
21
  attr_reader :logger
22
22
 
23
23
  delegate :audit_log_path, :audit_log_shift_age, :audit_log_shift_size, :audit_log_shift_period_suffix,
24
- :auditing_enabled,
24
+ :auditing_enabled, :audit_log_timezone,
25
25
  to: :configuration
26
26
 
27
27
  def configure
@@ -40,7 +40,8 @@ module AuditLoggable
40
40
  self.audit_log_path,
41
41
  shift_age: self.audit_log_shift_age,
42
42
  shift_size: self.audit_log_shift_size,
43
- shift_period_suffix: self.audit_log_shift_period_suffix
43
+ shift_period_suffix: self.audit_log_shift_period_suffix,
44
+ timezone: self.audit_log_timezone
44
45
  )
45
46
  end
46
47
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: audit_loggable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuji Hanamura
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-29 00:00:00.000000000 Z
11
+ date: 2022-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -144,6 +144,7 @@ files:
144
144
  - bin/setup
145
145
  - gemfiles/rails_6.0.gemfile
146
146
  - gemfiles/rails_6.1.gemfile
147
+ - gemfiles/rails_7.0.gemfile
147
148
  - lib/audit_loggable.rb
148
149
  - lib/audit_loggable/audit_record.rb
149
150
  - lib/audit_loggable/audit_record_set.rb
@@ -162,6 +163,7 @@ metadata:
162
163
  homepage_uri: https://github.com/vividgarden/audit_loggable
163
164
  source_code_uri: https://github.com/vividgarden/audit_loggable
164
165
  changelog_uri: https://github.com/vividgarden/audit_loggable/blob/main/CHANGELOG.md
166
+ rubygems_mfa_required: 'true'
165
167
  post_install_message:
166
168
  rdoc_options: []
167
169
  require_paths:
@@ -170,14 +172,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
170
172
  requirements:
171
173
  - - ">="
172
174
  - !ruby/object:Gem::Version
173
- version: '2.5'
175
+ version: '2.7'
174
176
  required_rubygems_version: !ruby/object:Gem::Requirement
175
177
  requirements:
176
178
  - - ">="
177
179
  - !ruby/object:Gem::Version
178
180
  version: '0'
179
181
  requirements: []
180
- rubygems_version: 3.2.3
182
+ rubygems_version: 3.3.7
181
183
  signing_key:
182
184
  specification_version: 4
183
185
  summary: Log changes to your models