temporal_tables 0.6.9 → 0.6.10

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: 9863a5343174db0c24c2d0019fd9403d196824cc13cb3438598e8f8d950be485
4
- data.tar.gz: 5aa981d770362f0a8a341991cf18cd0a7ea1e2dda5719275d03445b82f6f28ad
3
+ metadata.gz: e2c3cea031083df1bc590ff4e74869b1574b4a312145692efe11c6cd616dfc31
4
+ data.tar.gz: 928adaf78e5bfb5dfbfb57e942755bba2609be2a82d482544799ac4db25cabd4
5
5
  SHA512:
6
- metadata.gz: 1bc55839b61a4c816c650994ea297c1ea9a3fc9b9f37c3a89529c77c9e81e6049cd052707198c3b14501f0aec810c3e7a7350d5d94d1aa57e9ffbf3c9ee0255a
7
- data.tar.gz: 7026b3448055ebf8eb1bcbf77898bff845eca5bcb728a4bed53dd40c562ec0710e9fe3eb3c7631394d8c2c137b0d1ad6f2b179b2951491d6da95e12983e51edc
6
+ metadata.gz: 5312c5a461f6ae0546a6173b8618e21649bc76dec62ece50245135da97a19caf570323da027556cb5517045bdd3c8340a201bcfc582c0d0d5d52995d20079ea2
7
+ data.tar.gz: fe4b025bd68e8ea38c2d69eb942949cbb3a015ec9f20e9409d67d639d51cd2fadd5cb84d5fbd81c7ff0bdbddd1722fcc410970b0056f5f6d71539a119f83539e
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- temporal_tables (0.6.9)
4
+ temporal_tables (0.6.10)
5
5
  rails (~> 5.0)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- temporal_tables (0.6.9)
4
+ temporal_tables (0.6.10)
5
5
  rails (~> 5.0)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- temporal_tables (0.6.9)
4
+ temporal_tables (0.6.10)
5
5
  rails (~> 5.0)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- temporal_tables (0.6.9)
4
+ temporal_tables (0.6.10)
5
5
  rails (~> 5.0)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- temporal_tables (0.6.9)
4
+ temporal_tables (0.6.10)
5
5
  rails (~> 5.0)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- temporal_tables (0.6.9)
4
+ temporal_tables (0.6.10)
5
5
  rails (~> 5.0)
6
6
 
7
7
  GEM
@@ -0,0 +1,20 @@
1
+ module TemporalTables
2
+ # Uses the time from the "at" field stored in the record to filter queries
3
+ # made to associations.
4
+ module AssociationExtensions
5
+ def target_scope
6
+ # Kludge: Check +public_methods+ instead of using +responds_to?+ to
7
+ # bypass +delegate_missing_to+ calls, as in +ActiveStorage::Attachment+.
8
+ # Using responds_to? results in an infinite loop stack overflow.
9
+ if @owner.public_methods.include?(:at_value)
10
+ # If this is a history record but no at time was given,
11
+ # assume the record's effective to date
12
+ super.at(@owner.at_value || @owner.eff_to)
13
+ else
14
+ super
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ ActiveRecord::Associations::Association.prepend TemporalTables::AssociationExtensions
@@ -0,0 +1,20 @@
1
+ module TemporalTables
2
+ # This is required for eager_load to work in Rails 5.0.x
3
+ module JoinDependencyExtensions
4
+ def build_constraint(klass, table, key, foreign_table, foreign_key)
5
+ constraint = super
6
+ if at_value = Thread.current[:at_time]
7
+ constraint = constraint.and(klass.build_temporal_constraint(at_value))
8
+ end
9
+ constraint
10
+ end
11
+ end
12
+ end
13
+
14
+ case Rails::VERSION::MAJOR
15
+ when 5
16
+ case Rails::VERSION::MINOR
17
+ when 0, 1
18
+ ActiveRecord::Associations::JoinDependency::JoinAssociation.prepend TemporalTables::JoinDependencyExtensions
19
+ end
20
+ end
@@ -0,0 +1,19 @@
1
+ module TemporalTables
2
+ # Uses the at time when fetching preloaded records
3
+ module PreloaderExtensions
4
+ def build_scope
5
+ # It seems the at time can be in either of these places, but not both,
6
+ # depending on when the preloading happens to be done
7
+ at_time = @owners.first.at_value if @owners.first.respond_to?(:at_value)
8
+ at_time ||= Thread.current[:at_time]
9
+
10
+ if at_time
11
+ super.at(at_time)
12
+ else
13
+ super
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+ ActiveRecord::Associations::Preloader::Association.prepend TemporalTables::PreloaderExtensions
@@ -0,0 +1,21 @@
1
+ module TemporalTables
2
+ # This is required for eager_load to work in Rails 5.2.x
3
+ module AbstractReflectionExtensions
4
+ def build_join_constraint(table, foreign_table)
5
+ constraint = super
6
+ if at_value = Thread.current[:at_time]
7
+ constraint = constraint.and(klass.build_temporal_constraint(at_value))
8
+ end
9
+ constraint
10
+ end
11
+ end
12
+ end
13
+
14
+ case Rails::VERSION::MAJOR
15
+ when 5
16
+ case Rails::VERSION::MINOR
17
+ when 2
18
+ ActiveRecord::Reflection::AbstractReflection.prepend TemporalTables::AbstractReflectionExtensions
19
+ end
20
+ end
21
+
@@ -32,18 +32,7 @@ module TemporalTables
32
32
 
33
33
  def at!(value)
34
34
  self.at_value = value
35
- self
36
- end
37
-
38
- def where_clause
39
- s = super
40
-
41
- at_clauses = []
42
- if historical?
43
- at_clauses << where_clause_factory.build(build_temporal_constraint(at_value), [])
44
- end
45
-
46
- [s, *at_clauses.compact].sum
35
+ self.where!(klass.build_temporal_constraint(value))
47
36
  end
48
37
 
49
38
  def to_sql(*args)
@@ -100,53 +89,6 @@ module TemporalTables
100
89
  end
101
90
  end
102
91
  end
103
-
104
- # Uses the time from the "at" field stored in the record to filter queries
105
- # made to associations.
106
- module AssociationExtensions
107
- def target_scope
108
- # Kludge: Check +public_methods+ instead of using +responds_to?+ to
109
- # bypass +delegate_missing_to+ calls, as in +ActiveStorage::Attachment+.
110
- # Using responds_to? results in an infinite loop stack overflow.
111
- if @owner.public_methods.include?(:at_value)
112
- # If this is a history record but no at time was given,
113
- # assume the record's effective to date
114
- super.at(@owner.at_value || @owner.eff_to)
115
- else
116
- super
117
- end
118
- end
119
- end
120
-
121
- # Uses the at time when fetching preloaded records
122
- module PreloaderExtensions
123
- def build_scope
124
- # It seems the at time can be in either of these places, but not both,
125
- # depending on when the preloading happens to be done
126
- at_time = @owners.first.at_value if @owners.first.respond_to?(:at_value)
127
- at_time ||= Thread.current[:at_time]
128
-
129
- if at_time
130
- super.at(at_time)
131
- else
132
- super
133
- end
134
- end
135
- end
136
-
137
- # This is required for eager_load to work in Rails 5.0.x
138
- module JoinDependencyExtensions
139
- def build_constraint(klass, table, key, foreign_table, foreign_key)
140
- constraint = super
141
- if at_value = Thread.current[:at_time]
142
- constraint = constraint.and(klass.build_temporal_constraint(at_value))
143
- end
144
- constraint
145
- end
146
- end
147
92
  end
148
93
 
149
- ActiveRecord::Relation.send :prepend, TemporalTables::RelationExtensions
150
- ActiveRecord::Associations::Association.send :prepend, TemporalTables::AssociationExtensions
151
- ActiveRecord::Associations::Preloader::Association.send :prepend, TemporalTables::PreloaderExtensions
152
- ActiveRecord::Associations::JoinDependency::JoinAssociation.send :prepend, TemporalTables::JoinDependencyExtensions
94
+ ActiveRecord::Relation.prepend TemporalTables::RelationExtensions
@@ -1,3 +1,3 @@
1
1
  module TemporalTables
2
- VERSION = "0.6.9"
2
+ VERSION = "0.6.10"
3
3
  end
@@ -5,6 +5,10 @@ require "temporal_tables/whodunnit"
5
5
  require "temporal_tables/temporal_class"
6
6
  require "temporal_tables/history_hook"
7
7
  require "temporal_tables/relation_extensions"
8
+ require "temporal_tables/association_extensions"
9
+ require "temporal_tables/join_extensions"
10
+ require "temporal_tables/preloader_extensions"
11
+ require "temporal_tables/reflection_extensions"
8
12
  require "temporal_tables/version"
9
13
 
10
14
  module TemporalTables
@@ -74,6 +74,20 @@ describe Person do
74
74
  it 'should include the correct time' do
75
75
  expect(orig_emily.warts).to be_empty
76
76
  end
77
+
78
+ it 'should generate sensible sql' do
79
+ sql = emily.history.at(@init_time).eager_load(:warts).where(Wart.history.arel_table[:hairiness].gteq(2)).to_sql.split(/(FROM)|(WHERE)|(ORDER)/)
80
+ from = sql[2]
81
+ where = sql[4]
82
+
83
+ expect(from.scan(/.warts_h.\..eff_from./i).count).to eq(1)
84
+ expect(from.scan(/.warts_h.\..eff_to./i).count).to eq(1)
85
+
86
+ expect(where.scan(/.people_h.\..eff_from./i).count).to eq(1)
87
+ expect(where.scan(/.people_h.\..eff_to./i).count).to eq(1)
88
+ expect(where.scan(/.warts_h.\..eff_from./i).count).to eq(0)
89
+ expect(where.scan(/.warts_h.\..eff_to./i).count).to eq(0)
90
+ end
77
91
  end
78
92
 
79
93
  describe "when checking simple code values" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: temporal_tables
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.9
4
+ version: 0.6.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brent Kroeker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-11 00:00:00.000000000 Z
11
+ date: 2019-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -97,9 +97,13 @@ files:
97
97
  - gemfiles/Gemfile.5.2.pg
98
98
  - gemfiles/Gemfile.5.2.pg.lock
99
99
  - lib/temporal_tables.rb
100
+ - lib/temporal_tables/association_extensions.rb
100
101
  - lib/temporal_tables/connection_adapters/mysql_adapter.rb
101
102
  - lib/temporal_tables/connection_adapters/postgresql_adapter.rb
102
103
  - lib/temporal_tables/history_hook.rb
104
+ - lib/temporal_tables/join_extensions.rb
105
+ - lib/temporal_tables/preloader_extensions.rb
106
+ - lib/temporal_tables/reflection_extensions.rb
103
107
  - lib/temporal_tables/relation_extensions.rb
104
108
  - lib/temporal_tables/temporal_adapter.rb
105
109
  - lib/temporal_tables/temporal_class.rb