activerecord-bitemporal 5.3.0 → 6.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.
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ActiveRecord
4
4
  module Bitemporal
5
- VERSION = "5.3.0"
5
+ VERSION = "6.1.0"
6
6
  end
7
7
  end
@@ -22,7 +22,7 @@ module ActiveRecord::Bitemporal
22
22
  module_function
23
23
 
24
24
  def visualize(record, height: 10, width: 40, highlight: true)
25
- histories = record.class.ignore_bitemporal_datetime.bitemporal_for(record).order(:transaction_from, :valid_from)
25
+ histories = record.class.ignore_bitemporal_datetime.bitemporal_for(record).order(:transaction_from, record.valid_from_key)
26
26
 
27
27
  if highlight
28
28
  visualize_records(histories, [record], height: height, width: width)
@@ -36,7 +36,7 @@ module ActiveRecord::Bitemporal
36
36
  raise 'More than 3 relations are not supported' if relations.size >= 3
37
37
  records = relations.flatten
38
38
 
39
- valid_times = (records.map(&:valid_from) + records.map(&:valid_to)).sort.uniq
39
+ valid_times = (records.map { _1[_1.valid_from_key] } + records.map { _1[_1.valid_to_key] }).sort.uniq
40
40
  transaction_times = (records.map(&:transaction_from) + records.map(&:transaction_to)).sort.uniq
41
41
 
42
42
  time_length = Time.zone.now.strftime('%F %T.%3N').length
@@ -60,9 +60,11 @@ module ActiveRecord::Bitemporal
60
60
 
61
61
  relation.each do |record|
62
62
  line = lines[record.transaction_from]
63
- column = columns[record.valid_from]
63
+ valid_from = record[record.valid_from_key]
64
+ valid_to = record[record.valid_to_key]
65
+ column = columns[valid_from]
64
66
 
65
- width = columns[record.valid_to] - columns[record.valid_from] - 1
67
+ width = columns[valid_to] - columns[valid_from] - 1
66
68
  height = lines[record.transaction_to] - lines[record.transaction_from] - 1
67
69
 
68
70
  body.print("#{record.transaction_from.strftime('%F %T.%3N')} ", line: line)
@@ -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,146 +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 valid_from && valid_to && valid_from >= valid_to
96
- errors.add(:valid_from, "can't be greater equal than valid_to")
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
- )
112
- extend ClassMethods
113
- include InstanceMethods
114
- include ActiveRecord::Bitemporal::Scope
115
- include ActiveRecord::Bitemporal::Callbacks
116
-
117
- if enable_merge_with_except_bitemporal_default_scope
118
- relation_delegate_class(ActiveRecord::Relation).prepend ActiveRecord::Bitemporal::Relation::MergeWithExceptBitemporalDefaultScope
119
- end
120
-
121
- if enable_default_scope
122
- default_scope {
123
- bitemporal_default_scope
124
- }
125
- end
126
-
127
- after_create do
128
- # MEMO: #update_columns is not call #_update_row (and validations, callbacks)
129
- update_columns(bitemporal_id_key => swapped_id) unless send(bitemporal_id_key)
130
- swap_id!(without_clear_changes_information: true)
131
- @previously_force_updated = false
132
- end
133
-
134
- after_find do
135
- self.swap_id! if self.send(bitemporal_id_key).present?
136
- @previously_force_updated = false
137
- end
138
-
139
- attribute :valid_from, default: ActiveRecord::Bitemporal::DEFAULT_VALID_FROM
140
- attribute :valid_to, default: ActiveRecord::Bitemporal::DEFAULT_VALID_TO
141
- attribute :transaction_from, default: ActiveRecord::Bitemporal::DEFAULT_TRANSACTION_FROM
142
- attribute :transaction_to, default: ActiveRecord::Bitemporal::DEFAULT_TRANSACTION_TO
143
-
144
- # Callback hook to `validates :xxx, uniqueness: true`
145
- const_set(:UniquenessValidator, Class.new(ActiveRecord::Validations::UniquenessValidator) {
146
- prepend ActiveRecord::Bitemporal::Uniqueness
147
- })
148
-
149
- # validations
150
- validates :valid_from, presence: true
151
- validates :valid_to, presence: true
152
- validates :transaction_from, presence: true
153
- validates :transaction_to, presence: true
154
- validate :valid_from_cannot_be_greater_equal_than_valid_to
155
- validate :transaction_from_cannot_be_greater_equal_than_transaction_to
156
-
157
- validates bitemporal_id_key, uniqueness: true, allow_nil: true, strict: enable_strict_by_validates_bitemporal_id
158
-
159
- prepend_relation_delegate_class ActiveRecord::Bitemporal::Relation
160
- relation_delegate_class(ActiveRecord::Associations::CollectionProxy).prepend ActiveRecord::Bitemporal::CollectionProxy
161
- end
162
- end
163
-
164
24
  ActiveSupport.on_load(:active_record) do
25
+ require "activerecord-bitemporal/bitemporal"
26
+ require "activerecord-bitemporal/bitemporalize"
27
+ require "activerecord-bitemporal/patches"
28
+
165
29
  ActiveRecord::Base
166
30
  .extend ActiveRecord::Bitemporal::Bitemporalize
167
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: 5.3.0
4
+ version: 6.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - SmartHR
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2025-01-16 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,14 +15,28 @@ dependencies:
16
15
  requirements:
17
16
  - - ">="
18
17
  - !ruby/object:Gem::Version
19
- version: '6.1'
18
+ version: '7.0'
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: '6.1'
25
+ version: '7.0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: activesupport
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '7.0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '7.0'
27
40
  - !ruby/object:Gem::Dependency
28
41
  name: bundler
29
42
  requirement: !ruby/object:Gem::Requirement
@@ -38,6 +51,20 @@ dependencies:
38
51
  - - ">="
39
52
  - !ruby/object:Gem::Version
40
53
  version: '0'
54
+ - !ruby/object:Gem::Dependency
55
+ name: globalid
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ type: :development
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
41
68
  - !ruby/object:Gem::Dependency
42
69
  name: rake
43
70
  requirement: !ruby/object:Gem::Requirement
@@ -129,30 +156,16 @@ executables: []
129
156
  extensions: []
130
157
  extra_rdoc_files: []
131
158
  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
159
  - CHANGELOG.md
139
- - CODE_OF_CONDUCT.jp.md
140
- - CODE_OF_CONDUCT.md
141
- - Gemfile
142
160
  - LICENSE
143
161
  - README.md
144
- - Rakefile
145
- - activerecord-bitemporal.gemspec
146
- - bin/console
147
- - bin/setup
148
- - compose.yml
149
- - gemfiles/rails_6.1.gemfile
150
- - gemfiles/rails_7.0.gemfile
151
- - gemfiles/rails_7.1.gemfile
152
162
  - lib/activerecord-bitemporal.rb
153
163
  - lib/activerecord-bitemporal/bitemporal.rb
164
+ - lib/activerecord-bitemporal/bitemporal_checker.rb
165
+ - lib/activerecord-bitemporal/bitemporalize.rb
154
166
  - lib/activerecord-bitemporal/callbacks.rb
155
167
  - lib/activerecord-bitemporal/errors.rb
168
+ - lib/activerecord-bitemporal/global_id.rb
156
169
  - lib/activerecord-bitemporal/patches.rb
157
170
  - lib/activerecord-bitemporal/scope.rb
158
171
  - lib/activerecord-bitemporal/version.rb
@@ -161,7 +174,6 @@ homepage: https://github.com/kufu/activerecord-bitemporal
161
174
  licenses:
162
175
  - Apache 2.0
163
176
  metadata: {}
164
- post_install_message:
165
177
  rdoc_options: []
166
178
  require_paths:
167
179
  - lib
@@ -169,15 +181,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
169
181
  requirements:
170
182
  - - ">="
171
183
  - !ruby/object:Gem::Version
172
- version: '3.0'
184
+ version: '3.1'
173
185
  required_rubygems_version: !ruby/object:Gem::Requirement
174
186
  requirements:
175
187
  - - ">="
176
188
  - !ruby/object:Gem::Version
177
189
  version: '0'
178
190
  requirements: []
179
- rubygems_version: 3.3.27
180
- signing_key:
191
+ rubygems_version: 3.6.9
181
192
  specification_version: 4
182
193
  summary: BiTemporal Data Model for ActiveRecord
183
194
  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
- - wata727
14
- - yono
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@v4
23
- with:
24
- fetch-depth: 0
25
-
26
- - uses: ruby/setup-ruby@v1
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,54 +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.0'
19
- - '3.1'
20
- - '3.2'
21
- - '3.3'
22
- gemfile:
23
- - rails_6.1
24
- - rails_7.0
25
- - rails_7.1
26
- exclude:
27
- - ruby-version: '3.2'
28
- gemfile: rails_6.1
29
- - ruby-version: '3.3'
30
- gemfile: rails_6.1
31
- services:
32
- postgres:
33
- image: postgres:14
34
- env:
35
- POSTGRES_PASSWORD: postgres
36
- # Set health checks to wait until postgres has started
37
- options: >-
38
- --health-cmd pg_isready
39
- --health-interval 10s
40
- --health-timeout 5s
41
- --health-retries 5
42
- ports:
43
- - 5432:5432
44
- env:
45
- BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile
46
- steps:
47
- - name: Checkout
48
- uses: actions/checkout@v4
49
- - name: Setup Ruby
50
- uses: ruby/setup-ruby@v1
51
- with:
52
- ruby-version: ${{ matrix.ruby-version }}
53
- bundler-cache: true
54
- - 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,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- appraise "rails-6.1" do
4
- gem "rails", "~> 6.1.0"
5
- end
6
-
7
- appraise "rails-7.0" do
8
- gem "rails", "~> 7.0.1"
9
- end
10
-
11
- appraise "rails-7.1" do
12
- gem "rails", "~> 7.1.0"
13
- 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 で入手できます。