activerecord-bitemporal 6.0.0 → 7.0.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.
@@ -2,13 +2,12 @@
2
2
 
3
3
  require "active_record"
4
4
  require "active_support/core_ext/time/calculations"
5
- require "activerecord-bitemporal/bitemporal"
6
5
  require "activerecord-bitemporal/scope"
7
6
  require "activerecord-bitemporal/errors"
8
- require "activerecord-bitemporal/patches"
9
7
  require "activerecord-bitemporal/version"
10
8
  require "activerecord-bitemporal/visualizer"
11
9
  require "activerecord-bitemporal/callbacks"
10
+ require "activerecord-bitemporal/global_id"
12
11
 
13
12
  module ActiveRecord::Bitemporal
14
13
  DEFAULT_VALID_FROM = Time.utc(1900, 12, 31).in_time_zone.freeze
@@ -22,154 +21,11 @@ module ActiveRecord::Bitemporal
22
21
  end
23
22
  end
24
23
 
25
- module ActiveRecord::Bitemporal::Bitemporalize
26
- using Module.new {
27
- refine ::ActiveRecord::Base do
28
- class << ::ActiveRecord::Base
29
- def prepend_relation_delegate_class(mod)
30
- relation_delegate_class(ActiveRecord::Relation).prepend mod
31
- relation_delegate_class(ActiveRecord::AssociationRelation).prepend mod
32
- end
33
- end
34
- end
35
- }
36
-
37
- module ClassMethods
38
- include ActiveRecord::Bitemporal::Relation::Finder
39
-
40
- def bitemporal_id_key
41
- 'bitemporal_id'
42
- end
43
-
44
- # Override ActiveRecord::Core::ClassMethods#cached_find_by_statement
45
- # `.find_by` not use caching
46
- def cached_find_by_statement(key, &block)
47
- ActiveRecord::StatementCache.create(connection, &block)
48
- end
49
-
50
- def inherited(klass)
51
- super
52
- klass.prepend_relation_delegate_class ActiveRecord::Bitemporal::Relation
53
- klass.relation_delegate_class(ActiveRecord::Associations::CollectionProxy).prepend ActiveRecord::Bitemporal::CollectionProxy
54
- if relation_delegate_class(ActiveRecord::Relation).ancestors.include? ActiveRecord::Bitemporal::Relation::MergeWithExceptBitemporalDefaultScope
55
- klass.relation_delegate_class(ActiveRecord::Relation).prepend ActiveRecord::Bitemporal::Relation::MergeWithExceptBitemporalDefaultScope
56
- end
57
- end
58
- end
59
-
60
- module InstanceMethods
61
- include ActiveRecord::Bitemporal::Persistence
62
-
63
- def swap_id!(without_clear_changes_information: false)
64
- @_swapped_id_previously_was = nil
65
- @_swapped_id = self.id
66
- self.id = self.send(bitemporal_id_key)
67
- clear_attribute_changes([:id]) unless without_clear_changes_information
68
- end
69
-
70
- def swapped_id
71
- @_swapped_id || self.id
72
- end
73
-
74
- def swapped_id_previously_was
75
- @_swapped_id_previously_was
76
- end
77
-
78
- def bitemporal_id_key
79
- self.class.bitemporal_id_key
80
- end
81
-
82
- def bitemporal_ignore_update_columns
83
- []
84
- end
85
-
86
- def id_in_database
87
- swapped_id.presence || super
88
- end
89
-
90
- def previously_force_updated?
91
- @previously_force_updated
92
- end
93
-
94
- def valid_from_cannot_be_greater_equal_than_valid_to
95
- if self[valid_from_key] && self[valid_to_key] && self[valid_from_key] >= self[valid_to_key]
96
- errors.add(valid_from_key, "can't be greater equal than #{valid_to_key}")
97
- end
98
- end
99
-
100
- def transaction_from_cannot_be_greater_equal_than_transaction_to
101
- if transaction_from && transaction_to && transaction_from >= transaction_to
102
- errors.add(:transaction_from, "can't be greater equal than transaction_to")
103
- end
104
- end
105
- end
106
-
107
- def bitemporalize(
108
- enable_strict_by_validates_bitemporal_id: false,
109
- enable_default_scope: true,
110
- enable_merge_with_except_bitemporal_default_scope: false,
111
- valid_from_key: :valid_from,
112
- valid_to_key: :valid_to
113
- )
114
- return if ancestors.include? InstanceMethods
115
-
116
- extend ClassMethods
117
- include InstanceMethods
118
- include ActiveRecord::Bitemporal
119
- include ActiveRecord::Bitemporal::Scope
120
- include ActiveRecord::Bitemporal::Callbacks
121
-
122
- if enable_merge_with_except_bitemporal_default_scope
123
- relation_delegate_class(ActiveRecord::Relation).prepend ActiveRecord::Bitemporal::Relation::MergeWithExceptBitemporalDefaultScope
124
- end
125
-
126
- if enable_default_scope
127
- default_scope {
128
- bitemporal_default_scope
129
- }
130
- end
131
-
132
- after_create do
133
- # MEMO: #update_columns is not call #_update_row (and validations, callbacks)
134
- update_columns(bitemporal_id_key => swapped_id) unless send(bitemporal_id_key)
135
- swap_id!(without_clear_changes_information: true)
136
- @previously_force_updated = false
137
- end
138
-
139
- after_find do
140
- self.swap_id! if self.send(bitemporal_id_key).present?
141
- @previously_force_updated = false
142
- end
143
-
144
- self.class_attribute :valid_from_key, :valid_to_key, instance_writer: false
145
- self.valid_from_key = valid_from_key.to_s
146
- self.valid_to_key = valid_to_key.to_s
147
- attribute valid_from_key, default: ActiveRecord::Bitemporal::DEFAULT_VALID_FROM
148
- attribute valid_to_key, default: ActiveRecord::Bitemporal::DEFAULT_VALID_TO
149
- attribute :transaction_from, default: ActiveRecord::Bitemporal::DEFAULT_TRANSACTION_FROM
150
- attribute :transaction_to, default: ActiveRecord::Bitemporal::DEFAULT_TRANSACTION_TO
151
-
152
- # Callback hook to `validates :xxx, uniqueness: true`
153
- const_set(:UniquenessValidator, Class.new(ActiveRecord::Validations::UniquenessValidator) {
154
- prepend ActiveRecord::Bitemporal::Uniqueness
155
- })
156
-
157
- # validations
158
- validates valid_from_key, presence: true
159
- validates valid_to_key, presence: true
160
- validates :transaction_from, presence: true
161
- validates :transaction_to, presence: true
162
- validate :valid_from_cannot_be_greater_equal_than_valid_to
163
- validate :transaction_from_cannot_be_greater_equal_than_transaction_to
164
-
165
- validates bitemporal_id_key, uniqueness: true, allow_nil: true, strict: enable_strict_by_validates_bitemporal_id
166
-
167
- prepend_relation_delegate_class ActiveRecord::Bitemporal::Relation
168
- relation_delegate_class(ActiveRecord::Associations::CollectionProxy).prepend ActiveRecord::Bitemporal::CollectionProxy
169
- end
170
- end
171
-
172
24
  ActiveSupport.on_load(:active_record) do
25
+ require "activerecord-bitemporal/bitemporal"
26
+ require "activerecord-bitemporal/bitemporalize"
27
+ require "activerecord-bitemporal/patches"
28
+
173
29
  ActiveRecord::Base
174
30
  .extend ActiveRecord::Bitemporal::Bitemporalize
175
31
 
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-bitemporal
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.0
4
+ version: 7.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - SmartHR
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2025-06-02 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: activerecord
@@ -16,112 +15,28 @@ dependencies:
16
15
  requirements:
17
16
  - - ">="
18
17
  - !ruby/object:Gem::Version
19
- version: '7.0'
18
+ version: '7.1'
20
19
  type: :runtime
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
23
  - - ">="
25
24
  - !ruby/object:Gem::Version
26
- version: '7.0'
25
+ version: '7.1'
27
26
  - !ruby/object:Gem::Dependency
28
- name: bundler
27
+ name: activesupport
29
28
  requirement: !ruby/object:Gem::Requirement
30
29
  requirements:
31
30
  - - ">="
32
31
  - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: rake
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '13.0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '13.0'
55
- - !ruby/object:Gem::Dependency
56
- name: rspec
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '3.0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '3.0'
69
- - !ruby/object:Gem::Dependency
70
- name: pg
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: pry
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: pry-byebug
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
- - !ruby/object:Gem::Dependency
112
- name: timecop
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :development
32
+ version: '7.1'
33
+ type: :runtime
119
34
  prerelease: false
120
35
  version_requirements: !ruby/object:Gem::Requirement
121
36
  requirements:
122
37
  - - ">="
123
38
  - !ruby/object:Gem::Version
124
- version: '0'
39
+ version: '7.1'
125
40
  description: Enable ActiveRecord models to be handled as BiTemporal Data Model.
126
41
  email:
127
42
  - oss@smarthr.co.jp
@@ -129,30 +44,16 @@ executables: []
129
44
  extensions: []
130
45
  extra_rdoc_files: []
131
46
  files:
132
- - ".github/auto_assign.yml"
133
- - ".github/dependabot.yml"
134
- - ".github/workflows/release.yml"
135
- - ".github/workflows/test.yml"
136
- - ".gitignore"
137
- - Appraisals
138
47
  - CHANGELOG.md
139
- - CODE_OF_CONDUCT.jp.md
140
- - CODE_OF_CONDUCT.md
141
- - Gemfile
142
48
  - LICENSE
143
49
  - README.md
144
- - Rakefile
145
- - activerecord-bitemporal.gemspec
146
- - bin/console
147
- - bin/setup
148
- - compose.yml
149
- - gemfiles/rails_7.0.gemfile
150
- - gemfiles/rails_7.1.gemfile
151
- - gemfiles/rails_7.2.gemfile
152
50
  - lib/activerecord-bitemporal.rb
153
51
  - lib/activerecord-bitemporal/bitemporal.rb
52
+ - lib/activerecord-bitemporal/bitemporal_checker.rb
53
+ - lib/activerecord-bitemporal/bitemporalize.rb
154
54
  - lib/activerecord-bitemporal/callbacks.rb
155
55
  - lib/activerecord-bitemporal/errors.rb
56
+ - lib/activerecord-bitemporal/global_id.rb
156
57
  - lib/activerecord-bitemporal/patches.rb
157
58
  - lib/activerecord-bitemporal/scope.rb
158
59
  - lib/activerecord-bitemporal/version.rb
@@ -161,7 +62,6 @@ homepage: https://github.com/kufu/activerecord-bitemporal
161
62
  licenses:
162
63
  - Apache 2.0
163
64
  metadata: {}
164
- post_install_message:
165
65
  rdoc_options: []
166
66
  require_paths:
167
67
  - lib
@@ -176,8 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
176
76
  - !ruby/object:Gem::Version
177
77
  version: '0'
178
78
  requirements: []
179
- rubygems_version: 3.3.27
180
- signing_key:
79
+ rubygems_version: 4.0.7
181
80
  specification_version: 4
182
81
  summary: BiTemporal Data Model for ActiveRecord
183
82
  test_files: []
@@ -1,21 +0,0 @@
1
- # Set to true to add reviewers to pull requests
2
- addReviewers: true
3
-
4
- # Set to true to add assignees to pull requests
5
- addAssignees: false
6
-
7
- # A list of reviewers to be added to pull requests (GitHub user name)
8
- reviewers:
9
- - krororo
10
- - lighty
11
- - mkmn
12
- - osyo-manga
13
- - yono
14
- - kumaie-shr
15
-
16
- # A list of keywords to be skipped the process that add reviewers if pull requests include it
17
- skipKeywords:
18
-
19
- # A number of reviewers added to the pull request
20
- # Set 0 to add all the reviewers (default: 0)
21
- numberOfReviewers: 2
@@ -1,6 +0,0 @@
1
- version: 2
2
- updates:
3
- - package-ecosystem: "github-actions"
4
- directory: "/"
5
- schedule:
6
- interval: "weekly"
@@ -1,37 +0,0 @@
1
- name: Push to rubygems.org
2
-
3
- on:
4
- workflow_dispatch:
5
- inputs:
6
- rubygems-otp-code:
7
- description: RubyGems OTP code
8
- required: true
9
- type: string
10
- email:
11
- description: Your email
12
- required: true
13
- type: string
14
-
15
- jobs:
16
- release:
17
- runs-on: ubuntu-latest
18
- env:
19
- GEM_HOST_API_KEY: ${{ secrets.GEM_HOST_API_KEY }}
20
- GEM_HOST_OTP_CODE: ${{ github.event.inputs.rubygems-otp-code }}
21
- steps:
22
- - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
23
- with:
24
- fetch-depth: 0
25
-
26
- - uses: ruby/setup-ruby@13e7a03dc3ac6c3798f4570bfead2aed4d96abfb # v1.244.0
27
- with:
28
- ruby-version: '3.1'
29
- bundler-cache: true
30
-
31
- - name: config
32
- run: |
33
- git config --global user.email ${{ github.event.inputs.email }}
34
- git config --global user.name ${{ github.actor }}
35
-
36
- - name: release
37
- run: bundle exec rake release
@@ -1,49 +0,0 @@
1
- # yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
2
-
3
- name: Test
4
-
5
- on:
6
- push:
7
- branches:
8
- - master
9
- pull_request:
10
-
11
- jobs:
12
- test:
13
- runs-on: ubuntu-latest
14
- strategy:
15
- fail-fast: false
16
- matrix:
17
- ruby-version:
18
- - '3.1'
19
- - '3.2'
20
- - '3.3'
21
- - '3.4'
22
- gemfile:
23
- - rails_7.0
24
- - rails_7.1
25
- - rails_7.2
26
- services:
27
- postgres:
28
- image: postgres:14
29
- env:
30
- POSTGRES_PASSWORD: postgres
31
- # Set health checks to wait until postgres has started
32
- options: >-
33
- --health-cmd pg_isready
34
- --health-interval 10s
35
- --health-timeout 5s
36
- --health-retries 5
37
- ports:
38
- - 5432:5432
39
- env:
40
- BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile
41
- steps:
42
- - name: Checkout
43
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
44
- - name: Setup Ruby
45
- uses: ruby/setup-ruby@13e7a03dc3ac6c3798f4570bfead2aed4d96abfb # v1.244.0
46
- with:
47
- ruby-version: ${{ matrix.ruby-version }}
48
- bundler-cache: true
49
- - run: bundle exec rspec
data/.gitignore DELETED
@@ -1,4 +0,0 @@
1
- .bundle/
2
- .rspec_status
3
- Gemfile.lock
4
- gemfiles/*.gemfile.lock
data/Appraisals DELETED
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- appraise "rails-7.0" do
4
- gem "rails", "~> 7.0.1"
5
-
6
- # for Ruby 3.4
7
- gem "base64"
8
- gem "bigdecimal"
9
- gem "mutex_m"
10
-
11
- # NOTE: concurrent-ruby gem no longer loads the logger gem since v1.3.5.
12
- # https://github.com/ruby-concurrency/concurrent-ruby/pull/1062
13
- # https://github.com/rails/rails/pull/54264
14
- gem "concurrent-ruby", "< 1.3.5"
15
- end
16
-
17
- appraise "rails-7.1" do
18
- gem "rails", "~> 7.1.0"
19
- end
20
-
21
- appraise "rails-7.2" do
22
- gem "rails", "~> 7.2.0"
23
- end
@@ -1,86 +0,0 @@
1
- # コントリビューター行動規範
2
-
3
- ## 私たちの約束
4
- メンバー、コントリビューター、およびリーダーとして、年齢、体の大きさ、目に見えるまたは目に見えない障害、民族性、性別、
5
- 性同一性、表現、経験のレベル、教育、社会経済的地位、国籍、人格、人種、宗教、または性的同一性と指向に関係なく、
6
- コミュニティへの参加をハラスメントのない体験にすることを誓います。
7
-
8
- 私たちは、オープンで親しみやすく、多様で包括的で健全なコミュニティに貢献する方法で行動し、交流することを誓います。
9
-
10
- ## 私たちの標準
11
-
12
- 前向きな環境を作り上げることに貢献する行動の例:
13
-
14
- * 他人への共感と優しさを示す
15
-
16
- * 異なる意見、視点、経験を尊重する
17
-
18
- * 建設的なフィードバックを与え、優雅に受け入れる
19
-
20
- * 私たちの過ちの影響を受けた人々に責任を受け入れ、謝罪し、そしてその経験から学ぶ
21
-
22
- * 個人としてだけでなく、コミュニティ全体にとっても最善であることに焦点を当てる
23
-
24
- 許容できない行動の例は次のとおりです。
25
-
26
- * 性的な言葉や画像の使用、および性的な注意またはその他あらゆる種類の問題行為
27
-
28
- * トローリング、侮辱的または中傷的なコメント、個人的または政治的攻撃
29
-
30
- * 公的またはプライベートの嫌がらせ
31
-
32
- * 明示的な許可なしに、住所や電子メールアドレスなど、他者の個人情報を公開する
33
-
34
- * 職業上不適切と合理的に考えられるその他の行為
35
-
36
- ## 執行責任
37
-
38
- コミュニティリーダーは、許容される行動の基準を明確にし、実施する責任があり、不適切、脅迫的、攻撃的、または有害と見なされる行動に応じて、適切で公正な是正措置を講じます。
39
-
40
- コミュニティリーダーは、コメント、コミット、コード、wikiの編集、問題、およびこの行動規範に沿っていないその他の貢献を削除、編集、または拒否する権利と責任を持ち、適切な場合はモデレーションの決定の理由を伝えます。
41
-
42
- ## 適用範囲
43
-
44
- この行動規範は、すべてのコミュニティスペース内で適用され、個人がパブリックスペースでコミュニティを公式に代表している場合にも適用されます。
45
- 私たちのコミュニティを代表する例には、公式の電子メールアドレスの使用、公式のソーシャルメディアアカウントを介した投稿、オンラインまたはオフラインのイベントでの指定代理人としての行動などがあります。
46
-
47
- ## 執行
48
-
49
- 虐待的、嫌がらせ、またはその他の許容できない行動の事例は、執行を担当するコミュニティリーダーに対して `oss@smarthr.co.jp` で報告される場合があります。
50
- すべての苦情は迅速かつ公正にレビューおよび調査されます。
51
-
52
- すべてのコミュニティリーダーは、問題の報告者のプライバシーとセキュリティを尊重する義務があります。
53
-
54
- ## 執行ガイドライン
55
-
56
- コミュニティリーダーは、この行動規範に違反していると見なした行動への帰結を判断する際に、これらのコミュニティガイドラインに従います。
57
-
58
- ### 1. 更生
59
-
60
- **コミュニティへの影響**: コミュニティで専門家にふさわしくない、または歓迎されないと思われる不適切な言葉の使用やその他の不適切な行動をすること。
61
-
62
- **帰結**: コミュニティリーダーからの非公開の書面による警告。違反の理由を明確にし、行動が不適切だった理由を説明します。 公の謝罪が要求される場合があります。
63
-
64
- ### 2. 警告
65
-
66
- **コミュニティへの影響**: 単一の出来事または一連の動作による違反。
67
-
68
- **帰結**: 持続的な行動の結果を伴う警告。 指定された期間、行動規範の実施者との一方的な対話を含め、関係者との対話はありません。 これには、コミュニティスペースやソーシャルメディアなどの外部チャネルでの相互作用の回避が含まれます。 これらの条件に違反すると、一時的または永続的に禁止される場合があります。
69
-
70
- ### 3. 一時的な禁止
71
- **コミュニティへの影響**: 持続的で不適切な行動を含む、コミュニティ標準の重大な違反。
72
-
73
- **帰結**: 指定された期間のコミュニティとのあらゆる種類の相互関係または公的なコミュニケーションの一時的な禁止。 この期間中、行動規範を実施する人々との一方的な対話を含め、関係する人々との公的または私的な対話は許可されません。
74
- これらの条件に違反すると、永久的に禁止される場合があります。
75
- ### 4. 永久的な禁止
76
- **コミュニティへの影響**: 連続的な不適切な行動、個人への嫌がらせ、または個人の集団に対する攻撃または名誉毀損を含む、コミュニティの標準への違反のパターンを示す。
77
-
78
- **帰結**: コミュニティ内でのあらゆる種類の公的な相互関係の永久的な禁止。
79
-
80
- ## 帰属
81
- この行動規範は、https://www.contributor-covenant.org/version/2/0/code_of_conduct.html で利用可能な [Contributor Covenant][homepage] バージョン2.0を基に作成されています。
82
-
83
- コミュニティへの影響ガイドラインは[Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity)に適合しています。
84
-
85
- [homepage]: https://www.contributor-covenant.org
86
- この行動規範に関する一般的な質問への回答については、https://www.contributor-covenant.org/faq のFAQを参照してください。翻訳はhttps://www.contributor-covenant.org/translations で入手できます。