sequel_bitemporal 0.1.9 → 0.1.10
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/sequel/plugins/bitemporal.rb +14 -0
- data/sequel_bitemporal.gemspec +3 -3
- data/spec/bitemporal_date_spec.rb +38 -0
- metadata +21 -13
@@ -27,6 +27,20 @@ module Sequel
|
|
27
27
|
t = ::Sequel::Plugins::Bitemporal.point_in_time
|
28
28
|
ds.where{(created_at <= t) & ({expired_at=>nil} | (expired_at > t)) & (valid_from <= t) & (valid_to > t)}
|
29
29
|
end
|
30
|
+
master.def_dataset_method :with_current_version do
|
31
|
+
eager_graph(:current_version).where({current_version__id: nil}.sql_negate)
|
32
|
+
end
|
33
|
+
master.one_to_many :current_or_future_versions, class: version, key: :master_id, :graph_block=>(proc do |j, lj, js|
|
34
|
+
t = ::Sequel::Plugins::Bitemporal.point_in_time
|
35
|
+
e = :expired_at.qualify(j)
|
36
|
+
(:created_at.qualify(j) <= t) & ({e=>nil} | (e > t)) & (:valid_to.qualify(j) > t)
|
37
|
+
end) do |ds|
|
38
|
+
t = ::Sequel::Plugins::Bitemporal.point_in_time
|
39
|
+
ds.where{(created_at <= t) & ({expired_at=>nil} | (expired_at > t)) & (valid_to > t)}
|
40
|
+
end
|
41
|
+
master.def_dataset_method :with_current_or_future_versions do
|
42
|
+
eager_graph(:current_or_future_versions).where({current_or_future_versions__id: nil}.sql_negate)
|
43
|
+
end
|
30
44
|
version.many_to_one :master, class: master, key: :master_id
|
31
45
|
version.class_eval do
|
32
46
|
def current?(now = Time.now)
|
data/sequel_bitemporal.gemspec
CHANGED
@@ -3,9 +3,9 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "sequel_bitemporal"
|
6
|
-
s.version = "0.1.
|
7
|
-
s.authors = ["Joseph HALTER"]
|
8
|
-
s.email = ["joseph.halter@thetalentbox.com"]
|
6
|
+
s.version = "0.1.10"
|
7
|
+
s.authors = ["Joseph HALTER", "Jonathan TRON"]
|
8
|
+
s.email = ["joseph.halter@thetalentbox.com", "jonathan.tron@thetalentbox.com"]
|
9
9
|
s.homepage = "https://github.com/TalentBox/sequel_bitemporal"
|
10
10
|
s.summary = "Bitemporal versioning for sequel."
|
11
11
|
s.description = "Bitemporal versioning for sequel, fully tested."
|
@@ -299,6 +299,16 @@ describe "Sequel::Plugins::Bitemporal" do
|
|
299
299
|
master.destroy
|
300
300
|
@master_class.eager_graph(:current_version).where("current_version.id IS NOT NULL").first.should be_nil
|
301
301
|
end
|
302
|
+
it "allows loading masters with a current version" do
|
303
|
+
master_destroyed = @master_class.new
|
304
|
+
master_destroyed.update_attributes name: "Single Standard", price: 98
|
305
|
+
master_destroyed.destroy
|
306
|
+
master_with_current = @master_class.new
|
307
|
+
master_with_current.update_attributes name: "Single Standard", price: 94
|
308
|
+
master_with_future = @master_class.new
|
309
|
+
master_with_future.update_attributes name: "Single Standard", price: 94, valid_from: Date.today+2
|
310
|
+
@master_class.with_current_version.all.should have(1).item
|
311
|
+
end
|
302
312
|
it "gets pending or current version attributes" do
|
303
313
|
master = @master_class.new
|
304
314
|
master.attributes.should == {}
|
@@ -323,4 +333,32 @@ describe "Sequel::Plugins::Bitemporal" do
|
|
323
333
|
master.current_version(true).price.should == 98
|
324
334
|
end
|
325
335
|
end
|
336
|
+
it "allows eager loading with conditions on current or future versions" do
|
337
|
+
master = @master_class.new
|
338
|
+
master.update_attributes name: "Single Standard", price: 98
|
339
|
+
Timecop.freeze Date.today+1
|
340
|
+
master.update_attributes name: "Single Standard", price: 99
|
341
|
+
master.update_attributes name: "Single Standard", price: 94, valid_from: Date.today+2
|
342
|
+
res = @master_class.eager_graph(:current_or_future_versions).where({current_or_future_versions__id: nil}.sql_negate & {price: 99}).all.first
|
343
|
+
res.should be
|
344
|
+
res.current_or_future_versions.should have(1).item
|
345
|
+
res.current_or_future_versions.first.price.should == 99
|
346
|
+
res = @master_class.eager_graph(:current_or_future_versions).where({current_or_future_versions__id: nil}.sql_negate & {price: 94}).all.first
|
347
|
+
res.should be
|
348
|
+
res.current_or_future_versions.should have(1).item
|
349
|
+
res.current_or_future_versions.first.price.should == 94
|
350
|
+
Timecop.freeze Date.today+1
|
351
|
+
master.destroy
|
352
|
+
@master_class.eager_graph(:current_or_future_versions).where({current_or_future_versions__id: nil}.sql_negate).all.should be_empty
|
353
|
+
end
|
354
|
+
it "allows loading masters with current or future versions" do
|
355
|
+
master_destroyed = @master_class.new
|
356
|
+
master_destroyed.update_attributes name: "Single Standard", price: 98
|
357
|
+
master_destroyed.destroy
|
358
|
+
master_with_current = @master_class.new
|
359
|
+
master_with_current.update_attributes name: "Single Standard", price: 94
|
360
|
+
master_with_future = @master_class.new
|
361
|
+
master_with_future.update_attributes name: "Single Standard", price: 94, valid_from: Date.today+2
|
362
|
+
@master_class.with_current_or_future_versions.all.should have(2).item
|
363
|
+
end
|
326
364
|
end
|
metadata
CHANGED
@@ -1,19 +1,20 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sequel_bitemporal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.10
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Joseph HALTER
|
9
|
+
- Jonathan TRON
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date: 2011-11-11 00:00:00.
|
13
|
+
date: 2011-11-11 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: sequel
|
16
|
-
requirement: &
|
17
|
+
requirement: &2158291240 !ruby/object:Gem::Requirement
|
17
18
|
none: false
|
18
19
|
requirements:
|
19
20
|
- - ! '>='
|
@@ -21,10 +22,10 @@ dependencies:
|
|
21
22
|
version: '0'
|
22
23
|
type: :runtime
|
23
24
|
prerelease: false
|
24
|
-
version_requirements: *
|
25
|
+
version_requirements: *2158291240
|
25
26
|
- !ruby/object:Gem::Dependency
|
26
27
|
name: sqlite3
|
27
|
-
requirement: &
|
28
|
+
requirement: &2158290800 !ruby/object:Gem::Requirement
|
28
29
|
none: false
|
29
30
|
requirements:
|
30
31
|
- - ! '>='
|
@@ -32,10 +33,10 @@ dependencies:
|
|
32
33
|
version: '0'
|
33
34
|
type: :development
|
34
35
|
prerelease: false
|
35
|
-
version_requirements: *
|
36
|
+
version_requirements: *2158290800
|
36
37
|
- !ruby/object:Gem::Dependency
|
37
38
|
name: rspec
|
38
|
-
requirement: &
|
39
|
+
requirement: &2158290380 !ruby/object:Gem::Requirement
|
39
40
|
none: false
|
40
41
|
requirements:
|
41
42
|
- - ! '>='
|
@@ -43,10 +44,10 @@ dependencies:
|
|
43
44
|
version: '0'
|
44
45
|
type: :development
|
45
46
|
prerelease: false
|
46
|
-
version_requirements: *
|
47
|
+
version_requirements: *2158290380
|
47
48
|
- !ruby/object:Gem::Dependency
|
48
49
|
name: timecop
|
49
|
-
requirement: &
|
50
|
+
requirement: &2158289960 !ruby/object:Gem::Requirement
|
50
51
|
none: false
|
51
52
|
requirements:
|
52
53
|
- - ! '>='
|
@@ -54,10 +55,10 @@ dependencies:
|
|
54
55
|
version: '0'
|
55
56
|
type: :development
|
56
57
|
prerelease: false
|
57
|
-
version_requirements: *
|
58
|
+
version_requirements: *2158289960
|
58
59
|
- !ruby/object:Gem::Dependency
|
59
60
|
name: rake
|
60
|
-
requirement: &
|
61
|
+
requirement: &2158289540 !ruby/object:Gem::Requirement
|
61
62
|
none: false
|
62
63
|
requirements:
|
63
64
|
- - ! '>='
|
@@ -65,10 +66,11 @@ dependencies:
|
|
65
66
|
version: '0'
|
66
67
|
type: :development
|
67
68
|
prerelease: false
|
68
|
-
version_requirements: *
|
69
|
+
version_requirements: *2158289540
|
69
70
|
description: Bitemporal versioning for sequel, fully tested.
|
70
71
|
email:
|
71
72
|
- joseph.halter@thetalentbox.com
|
73
|
+
- jonathan.tron@thetalentbox.com
|
72
74
|
executables: []
|
73
75
|
extensions: []
|
74
76
|
extra_rdoc_files: []
|
@@ -97,15 +99,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
97
99
|
- - ! '>='
|
98
100
|
- !ruby/object:Gem::Version
|
99
101
|
version: '0'
|
102
|
+
segments:
|
103
|
+
- 0
|
104
|
+
hash: -2412870867383750431
|
100
105
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
106
|
none: false
|
102
107
|
requirements:
|
103
108
|
- - ! '>='
|
104
109
|
- !ruby/object:Gem::Version
|
105
110
|
version: '0'
|
111
|
+
segments:
|
112
|
+
- 0
|
113
|
+
hash: -2412870867383750431
|
106
114
|
requirements: []
|
107
115
|
rubyforge_project:
|
108
|
-
rubygems_version: 1.8.
|
116
|
+
rubygems_version: 1.8.10
|
109
117
|
signing_key:
|
110
118
|
specification_version: 3
|
111
119
|
summary: Bitemporal versioning for sequel.
|