activerecord-bitemporal-tablize 0.1.3 → 0.1.4
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.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '09a8d3ec50bd99cbd07b14fd9efab561697739d8aee8e7aa82ef9677e81885c3'
|
4
|
+
data.tar.gz: e13e3a01b35aac80b6feb6d92fc4dbc028f6da7e278f5e9039f9b09ed211857a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70b7cb9932c970f2ef0c9bcfa431c89265f27747dc49b6a9481b921a37016e19d00ded4c51210ec1d3e62bb9d8414050fde1e13b38c323e8c9f7920d49ef7fdf
|
7
|
+
data.tar.gz: 8116c05478d403487dfd09641f0a4ae4579add18bd3bb829d5cd5d0c8f49854ccfc842d66c91a401f903e7af5e0f96b2552ed614dbe890a899acbb32badbcda5
|
data/README.md
CHANGED
@@ -22,12 +22,21 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
ローカル環境でgem
|
25
|
+
1. ローカル環境でgemをインストールする
|
26
|
+
2. 以下を.pryrcなどに追加
|
27
|
+
- インストールされたパスをロードパスに含める
|
28
|
+
- requireする
|
29
|
+
```
|
30
|
+
# cat ~/.pryrc
|
31
|
+
$: << '/Users/lighty/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activerecord-bitemporal-tablize-0.1.3/lib/'
|
32
|
+
require 'activerecord-bitemporal-tablize'
|
33
|
+
```
|
34
|
+
|
26
35
|
|
27
36
|
ref: https://qiita.com/kyanny/items/d370efe14ef15d9afacb
|
28
37
|
|
29
38
|
```
|
30
|
-
[1] pry(main)> Employee.first.histories.
|
39
|
+
[1] pry(main)> Employee.first.histories.print_histories
|
31
40
|
(0.8ms) SELECT sqlite_version(*)
|
32
41
|
Employee Load (0.3ms) SELECT "employees".* FROM "employees" WHERE "employees"."valid_from" <= ? AND "employees"."valid_to" > ? AND "employees"."deleted_at" IS NULL ORDER BY "employees"."bitemporal_id" ASC LIMIT ? [["valid_from", "2021-06-20 13:21:42.229006"], ["valid_to", "2021-06-20 13:21:42.229006"], ["LIMIT", 1]]
|
33
42
|
Employee Load (0.2ms) SELECT "employees".* FROM "employees" WHERE "employees"."deleted_at" IS NULL AND "employees"."bitemporal_id" = ? ORDER BY "employees"."valid_from" DESC [["bitemporal_id", 1]]
|
@@ -40,7 +49,7 @@ ref: https://qiita.com/kyanny/items/d370efe14ef15d9afacb
|
|
40
49
|
| | 1 | 1 | たけし | | 2021-06-20 01:44:43 UTC | 2021-06-20 01:44:43 UTC | 1 | 2020/01/01 | 2021/04/01 | | 2021-06-20 01:44:43 UTC | 9999-12-31 00:00:00 UTC |
|
41
50
|
+-2020/01/01-+----+---------+--------+-----------+-------------------------+-------------------------+---------------+------------+------------+------------+-------------------------+-------------------------+
|
42
51
|
=> nil
|
43
|
-
[2] pry(main)> Employee.first.histories.
|
52
|
+
[2] pry(main)> Employee.first.histories.print_histories_diff
|
44
53
|
Employee Load (0.2ms) SELECT "employees".* FROM "employees" WHERE "employees"."valid_from" <= ? AND "employees"."valid_to" > ? AND "employees"."deleted_at" IS NULL ORDER BY "employees"."bitemporal_id" ASC LIMIT ? [["valid_from", "2021-06-20 13:21:44.302316"], ["valid_to", "2021-06-20 13:21:44.302316"], ["LIMIT", 1]]
|
45
54
|
Employee Load (0.1ms) SELECT "employees".* FROM "employees" WHERE "employees"."deleted_at" IS NULL AND "employees"."bitemporal_id" = ? ORDER BY "employees"."valid_from" DESC [["bitemporal_id", 1]]
|
46
55
|
+------------+---------+--------+-------------------------+------------+------------+
|
@@ -52,7 +61,7 @@ ref: https://qiita.com/kyanny/items/d370efe14ef15d9afacb
|
|
52
61
|
| | 1 | たけし | 2021-06-20 01:44:43 UTC | 2020/01/01 | 2021/04/01 |
|
53
62
|
+-2020/01/01-+---------+--------+-------------------------+------------+------------+
|
54
63
|
=> nil
|
55
|
-
[3] pry(main)> Employee.first.histories.
|
64
|
+
[3] pry(main)> Employee.first.histories.print_histories(:name)
|
56
65
|
Employee Load (0.2ms) SELECT "employees".* FROM "employees" WHERE "employees"."valid_from" <= ? AND "employees"."valid_to" > ? AND "employees"."deleted_at" IS NULL ORDER BY "employees"."bitemporal_id" ASC LIMIT ? [["valid_from", "2021-06-20 13:22:54.269095"], ["valid_to", "2021-06-20 13:22:54.269095"], ["LIMIT", 1]]
|
57
66
|
Employee Load (0.1ms) SELECT "employees".* FROM "employees" WHERE "employees"."deleted_at" IS NULL AND "employees"."bitemporal_id" = ? ORDER BY "employees"."valid_from" DESC [["bitemporal_id", 1]]
|
58
67
|
+------------+--------+
|
@@ -2,22 +2,23 @@ module ActiveRecord
|
|
2
2
|
module Bitemporal
|
3
3
|
module Bitemporalize
|
4
4
|
module InstanceMethods
|
5
|
-
def histories
|
6
|
-
records = begin
|
7
|
-
super
|
8
|
-
rescue NoMethodError
|
9
|
-
self.class.ignore_valid_datetime.bitemporal_for(bitemporal_id).order(valid_from: :desc)
|
10
|
-
end
|
11
5
|
|
12
|
-
|
13
|
-
|
14
|
-
|
6
|
+
def print_histories(*attributes)
|
7
|
+
print ActiveRecord::Bitemporal::Tablize.new(records: ordered_histories, attributes: attributes).call
|
8
|
+
end
|
9
|
+
|
10
|
+
def print_histories_diff
|
11
|
+
print ActiveRecord::Bitemporal::Tablize.new(records: ordered_histories, diff_only: true).call
|
12
|
+
end
|
15
13
|
|
16
|
-
|
17
|
-
print ActiveRecord::Bitemporal::Tablize.new(records: records, attributes: attributes, diff_only: true).call
|
18
|
-
end
|
14
|
+
private
|
19
15
|
|
20
|
-
|
16
|
+
def ordered_histories
|
17
|
+
if respond_to?(:histories)
|
18
|
+
histories
|
19
|
+
else
|
20
|
+
self.class.ignore_valid_datetime.bitemporal_for(bitemporal_id)
|
21
|
+
end.order(valid_from: :desc)
|
21
22
|
end
|
22
23
|
end
|
23
24
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-bitemporal-tablize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- lighty
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-07-14 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Displaying the history of records managed by ActiveRecord::Bitemporal
|
14
14
|
in a tabular format.
|
@@ -54,7 +54,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '0'
|
56
56
|
requirements: []
|
57
|
-
rubygems_version: 3.
|
57
|
+
rubygems_version: 3.0.3
|
58
58
|
signing_key:
|
59
59
|
specification_version: 4
|
60
60
|
summary: Displaying the history of records managed by ActiveRecord::Bitemporal in
|