activerecord-bitemporal-tablize 0.1.3 → 0.1.4

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: a31b7fe58c46784c45f3620b873bbd5a69e00ef41799505c1d3b5b361a446458
4
- data.tar.gz: bf4f8847a18a5dec5b18a2f75a8f6ec824dea6a2fa532b445e47df227ad87f7c
3
+ metadata.gz: '09a8d3ec50bd99cbd07b14fd9efab561697739d8aee8e7aa82ef9677e81885c3'
4
+ data.tar.gz: e13e3a01b35aac80b6feb6d92fc4dbc028f6da7e278f5e9039f9b09ed211857a
5
5
  SHA512:
6
- metadata.gz: 753493508c1d7ed7e7218f47b075e53124df60c6f255cc74934078acaf1fc831b52d69033b2715d8aa45154c2372acaaad882f2440a76fac042736c9c2eaf508
7
- data.tar.gz: 99a0984a0c5bd06be2097bb816f2452494f5bf82c7d381d87dad5df8922005d4f4d7c6257e8862e7c174ec45b6b52a6c39d219f13174fe17a5423b0c7c9355f2
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をインストールし、`rails console`した後でrequireする
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.print_table
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.print_table_diff_only
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.print_table(:name)
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
- records.define_singleton_method(:print_table) do |*attributes|
13
- print ActiveRecord::Bitemporal::Tablize.new(records: records, attributes: attributes).call
14
- end
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
- records.define_singleton_method(:print_table_diff_only) do |*attributes|
17
- print ActiveRecord::Bitemporal::Tablize.new(records: records, attributes: attributes, diff_only: true).call
18
- end
14
+ private
19
15
 
20
- records
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
@@ -3,7 +3,7 @@
3
3
  module Activerecord
4
4
  module Bitemporal
5
5
  module Tablize
6
- VERSION = '0.1.3'
6
+ VERSION = '0.1.4'
7
7
  end
8
8
  end
9
9
  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.3
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-06-21 00:00:00.000000000 Z
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.2.15
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