sequel_bitemporal 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,8 +8,13 @@ module Sequel
8
8
  missing = required - version.columns
9
9
  raise Error, "bitemporal plugin requires the following missing column#{"s" if missing.size>1} on version class: #{missing.join(", ")}" unless missing.empty?
10
10
  master.one_to_many :versions, class: version, key: :master_id
11
- master.one_to_one :current_version, class: version, key: :master_id do |ds|
12
- ds.where "created_at<=:now AND (expired_at IS NULL OR expired_at>:now) AND valid_from<=:now AND valid_to>:now", now: Time.now
11
+ master.one_to_one :current_version, class: version, key: :master_id, :graph_block=>(proc do |j, lj, js|
12
+ t = Time.now
13
+ e = :expired_at.qualify(j)
14
+ (:created_at.qualify(j) <= t) & ({e=>nil} | (e > t)) & (:valid_from.qualify(j) <= t) & (:valid_to.qualify(j) > t)
15
+ end) do |ds|
16
+ t = Time.now
17
+ ds.where{(created_at <= t) & ({expired_at=>nil} | (expired_at > t)) & (valid_from <= t) & (valid_to > t)}
13
18
  end
14
19
  version.many_to_one :master, class: master, key: :master_id
15
20
  version.class_eval do
@@ -3,7 +3,7 @@ $:.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.3"
6
+ s.version = "0.1.4"
7
7
  s.authors = ["Joseph HALTER"]
8
8
  s.email = ["joseph.halter@thetalentbox.com"]
9
9
  s.homepage = "https://github.com/TalentBox/sequel_bitemporal"
@@ -290,4 +290,13 @@ describe "Sequel::Plugins::Bitemporal" do
290
290
  | King Size | 94 | 2009-11-29 | | 2009-11-29 | | true |
291
291
  }
292
292
  end
293
+ it "allows eager loading with conditions on current version" do
294
+ master = @master_class.new
295
+ master.update_attributes name: "Single Standard", price: 98
296
+ master.update_attributes name: "Single Standard", price: 94, valid_from: Date.today+2
297
+ @master_class.eager_graph(:current_version).where("current_version.id IS NOT NULL").first.should_not be_nil
298
+ Timecop.freeze Date.today+1
299
+ master.destroy
300
+ @master_class.eager_graph(:current_version).where("current_version.id IS NOT NULL").first.should be_nil
301
+ end
293
302
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequel_bitemporal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-02 00:00:00.000000000Z
12
+ date: 2011-11-03 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sqlite3
16
- requirement: &2157973260 !ruby/object:Gem::Requirement
16
+ requirement: &2158312800 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *2157973260
24
+ version_requirements: *2158312800
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &2157972820 !ruby/object:Gem::Requirement
27
+ requirement: &2158312360 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2157972820
35
+ version_requirements: *2158312360
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: timecop
38
- requirement: &2158000040 !ruby/object:Gem::Requirement
38
+ requirement: &2158311940 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2158000040
46
+ version_requirements: *2158311940
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: sequel
49
- requirement: &2157999620 !ruby/object:Gem::Requirement
49
+ requirement: &2158311520 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *2157999620
57
+ version_requirements: *2158311520
58
58
  description: Bitemporal versioning for sequel, fully tested.
59
59
  email:
60
60
  - joseph.halter@thetalentbox.com