temporal_tables 0.6.6 → 0.6.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/gemfiles/Gemfile.5.0.mysql.lock +1 -1
- data/gemfiles/Gemfile.5.0.pg.lock +1 -1
- data/gemfiles/Gemfile.5.1.mysql.lock +1 -1
- data/gemfiles/Gemfile.5.1.pg.lock +1 -1
- data/gemfiles/Gemfile.5.2.mysql.lock +1 -1
- data/gemfiles/Gemfile.5.2.pg.lock +1 -1
- data/lib/temporal_tables/relation_extensions.rb +12 -6
- data/lib/temporal_tables/temporal_class.rb +6 -0
- data/lib/temporal_tables/version.rb +1 -1
- data/lib/temporal_tables.rb +0 -1
- data/spec/basic_history_spec.rb +16 -0
- data/spec/spec_helper.rb +1 -1
- metadata +1 -2
- data/lib/temporal_tables/scope_extensions.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff585572728100114c403af9f97e723d0c1d1760e73c46e7127d86849941cf0d
|
4
|
+
data.tar.gz: c3f7f8d672c1d549c378be20996ed8594f51c53bf215c820d864fa936e4f572e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39d574fec08e359020dc88b2b7ef9d03ac6206da04517643d0686dbf02e1ecf6834d03742afadffd564bd7573076863bd82b3259059f0697b25594f9261f4f69
|
7
|
+
data.tar.gz: 5493b7f16dd8cb2db633529037711ffb78224c5c42ab6e836f43901dacea20ade306e0103e09cc66f9349350e87da336032098cd7abb38430de18b5eb408a71e
|
@@ -40,12 +40,7 @@ module TemporalTables
|
|
40
40
|
|
41
41
|
at_clauses = []
|
42
42
|
if historical?
|
43
|
-
at_clauses << where_clause_factory.build(
|
44
|
-
arel_table[:eff_to].gteq(at_value).and(
|
45
|
-
arel_table[:eff_from].lteq(at_value)
|
46
|
-
),
|
47
|
-
[]
|
48
|
-
)
|
43
|
+
at_clauses << where_clause_factory.build(build_temporal_constraint(at_value), [])
|
49
44
|
end
|
50
45
|
|
51
46
|
[s, *at_clauses.compact].sum
|
@@ -139,8 +134,19 @@ module TemporalTables
|
|
139
134
|
end
|
140
135
|
end
|
141
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
|
142
147
|
end
|
143
148
|
|
144
149
|
ActiveRecord::Relation.send :prepend, TemporalTables::RelationExtensions
|
145
150
|
ActiveRecord::Associations::Association.send :prepend, TemporalTables::AssociationExtensions
|
146
151
|
ActiveRecord::Associations::Preloader::Association.send :prepend, TemporalTables::PreloaderExtensions
|
152
|
+
ActiveRecord::Associations::JoinDependency::JoinAssociation.send :prepend, TemporalTables::JoinDependencyExtensions
|
@@ -68,6 +68,12 @@ module TemporalTables
|
|
68
68
|
def descends_from_active_record?
|
69
69
|
superclass.descends_from_active_record?
|
70
70
|
end
|
71
|
+
|
72
|
+
def build_temporal_constraint(at_value)
|
73
|
+
arel_table[:eff_to].gteq(at_value).and(
|
74
|
+
arel_table[:eff_from].lteq(at_value)
|
75
|
+
)
|
76
|
+
end
|
71
77
|
end
|
72
78
|
|
73
79
|
def orig_class
|
data/lib/temporal_tables.rb
CHANGED
@@ -5,7 +5,6 @@ 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/scope_extensions"
|
9
8
|
require "temporal_tables/version"
|
10
9
|
|
11
10
|
module TemporalTables
|
data/spec/basic_history_spec.rb
CHANGED
@@ -92,5 +92,21 @@ describe Person do
|
|
92
92
|
expect(historical_emily.is_a?(PersonHistory)).to eq(true)
|
93
93
|
end
|
94
94
|
end
|
95
|
+
|
96
|
+
describe "when checking current state" do
|
97
|
+
it "should have correct information" do
|
98
|
+
# ie. we shouldn't break regular ActiveRecord behaviour
|
99
|
+
expect(Person.count).to eq(1)
|
100
|
+
expect(Wart.count).to eq(1)
|
101
|
+
|
102
|
+
emily = Person.first
|
103
|
+
expect(emily.warts.count).to eq(1)
|
104
|
+
expect(emily.warts.first.hairiness).to eq(3)
|
105
|
+
|
106
|
+
emily = Person.where(id: emily.id).eager_load(:warts).first
|
107
|
+
expect(emily.warts.count).to eq(1)
|
108
|
+
expect(emily.warts.first.hairiness).to eq(3)
|
109
|
+
end
|
110
|
+
end
|
95
111
|
end
|
96
112
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: temporal_tables
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brent Kroeker
|
@@ -101,7 +101,6 @@ files:
|
|
101
101
|
- lib/temporal_tables/connection_adapters/postgresql_adapter.rb
|
102
102
|
- lib/temporal_tables/history_hook.rb
|
103
103
|
- lib/temporal_tables/relation_extensions.rb
|
104
|
-
- lib/temporal_tables/scope_extensions.rb
|
105
104
|
- lib/temporal_tables/temporal_adapter.rb
|
106
105
|
- lib/temporal_tables/temporal_class.rb
|
107
106
|
- lib/temporal_tables/version.rb
|
@@ -1,13 +0,0 @@
|
|
1
|
-
module TemporalTables
|
2
|
-
module NamedExtensionsWithHistory
|
3
|
-
def scope(name, body, &block)
|
4
|
-
if history
|
5
|
-
history_body = -> { history.instance_exec &body }
|
6
|
-
history.scope_without_history name, history_body, &block
|
7
|
-
end
|
8
|
-
super name, body, &block
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
ActiveRecord::Scoping::Named::ClassMethods.send :prepend, TemporalTables::NamedExtensionsWithHistory
|