sequel_bitemporal 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ rvm:
2
+ - 1.9.2
3
+ - 1.9.3
4
+ notifications:
5
+ disabled: true
@@ -1,6 +1,17 @@
1
1
  module Sequel
2
2
  module Plugins
3
3
  module Bitemporal
4
+ def self.as_we_knew_it(time)
5
+ raise ArgumentError, "requires a block" unless block_given?
6
+ previous_point_in_time, @point_in_time = @point_in_time, time
7
+ yield
8
+ @point_in_time = previous_point_in_time
9
+ end
10
+
11
+ def self.point_in_time
12
+ @point_in_time || Time.now
13
+ end
14
+
4
15
  def self.configure(master, opts = {})
5
16
  version = opts[:version_class]
6
17
  raise Error, "please specify version class to use for bitemporal plugin" unless version
@@ -9,11 +20,11 @@ module Sequel
9
20
  raise Error, "bitemporal plugin requires the following missing column#{"s" if missing.size>1} on version class: #{missing.join(", ")}" unless missing.empty?
10
21
  master.one_to_many :versions, class: version, key: :master_id
11
22
  master.one_to_one :current_version, class: version, key: :master_id, :graph_block=>(proc do |j, lj, js|
12
- t = Time.now
23
+ t = ::Sequel::Plugins::Bitemporal.point_in_time
13
24
  e = :expired_at.qualify(j)
14
25
  (:created_at.qualify(j) <= t) & ({e=>nil} | (e > t)) & (:valid_from.qualify(j) <= t) & (:valid_to.qualify(j) > t)
15
26
  end) do |ds|
16
- t = Time.now
27
+ t = ::Sequel::Plugins::Bitemporal.point_in_time
17
28
  ds.where{(created_at <= t) & ({expired_at=>nil} | (expired_at > t)) & (valid_from <= t) & (valid_to > t)}
18
29
  end
19
30
  version.many_to_one :master, class: master, key: :master_id
@@ -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.7"
6
+ s.version = "0.1.8"
7
7
  s.authors = ["Joseph HALTER"]
8
8
  s.email = ["joseph.halter@thetalentbox.com"]
9
9
  s.homepage = "https://github.com/TalentBox/sequel_bitemporal"
@@ -15,8 +15,10 @@ Gem::Specification.new do |s|
15
15
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
16
  s.require_paths = ["lib"]
17
17
 
18
+ s.add_runtime_dependency "sequel"
19
+
18
20
  s.add_development_dependency "sqlite3"
19
21
  s.add_development_dependency "rspec"
20
22
  s.add_development_dependency "timecop"
21
- s.add_runtime_dependency "sequel"
23
+ s.add_development_dependency "rake"
22
24
  end
@@ -31,11 +31,11 @@ describe "Sequel::Plugins::Bitemporal" do
31
31
  end
32
32
  before do
33
33
  Timecop.freeze 2009, 11, 28
34
+ @master_class.truncate
35
+ @version_class.truncate
34
36
  end
35
37
  after do
36
38
  Timecop.return
37
- @master_class.truncate
38
- @version_class.truncate
39
39
  end
40
40
  it "checks version class is given" do
41
41
  lambda{
@@ -313,4 +313,14 @@ describe "Sequel::Plugins::Bitemporal" do
313
313
  master.pending_version.should be
314
314
  master.pending_or_current_version.name.should == "King Size"
315
315
  end
316
+ it "allows to go back in time" do
317
+ master = @master_class.new
318
+ master.update_attributes name: "Single Standard", price: 98
319
+ Timecop.freeze Date.today+1
320
+ master.update_attributes price: 94, partial_update: true
321
+ master.current_version.price.should == 94
322
+ Sequel::Plugins::Bitemporal.as_we_knew_it(Date.today-1) do
323
+ master.current_version(true).price.should == 98
324
+ end
325
+ end
316
326
  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.7
4
+ version: 0.1.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-07 00:00:00.000000000Z
12
+ date: 2011-11-08 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: sequel
16
+ requirement: &2152436900 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2152436900
14
25
  - !ruby/object:Gem::Dependency
15
26
  name: sqlite3
16
- requirement: &2157615300 !ruby/object:Gem::Requirement
27
+ requirement: &2152385280 !ruby/object:Gem::Requirement
17
28
  none: false
18
29
  requirements:
19
30
  - - ! '>='
@@ -21,10 +32,10 @@ dependencies:
21
32
  version: '0'
22
33
  type: :development
23
34
  prerelease: false
24
- version_requirements: *2157615300
35
+ version_requirements: *2152385280
25
36
  - !ruby/object:Gem::Dependency
26
37
  name: rspec
27
- requirement: &2157614860 !ruby/object:Gem::Requirement
38
+ requirement: &2152384260 !ruby/object:Gem::Requirement
28
39
  none: false
29
40
  requirements:
30
41
  - - ! '>='
@@ -32,10 +43,10 @@ dependencies:
32
43
  version: '0'
33
44
  type: :development
34
45
  prerelease: false
35
- version_requirements: *2157614860
46
+ version_requirements: *2152384260
36
47
  - !ruby/object:Gem::Dependency
37
48
  name: timecop
38
- requirement: &2157614440 !ruby/object:Gem::Requirement
49
+ requirement: &2152383300 !ruby/object:Gem::Requirement
39
50
  none: false
40
51
  requirements:
41
52
  - - ! '>='
@@ -43,18 +54,18 @@ dependencies:
43
54
  version: '0'
44
55
  type: :development
45
56
  prerelease: false
46
- version_requirements: *2157614440
57
+ version_requirements: *2152383300
47
58
  - !ruby/object:Gem::Dependency
48
- name: sequel
49
- requirement: &2157614020 !ruby/object:Gem::Requirement
59
+ name: rake
60
+ requirement: &2152382540 !ruby/object:Gem::Requirement
50
61
  none: false
51
62
  requirements:
52
63
  - - ! '>='
53
64
  - !ruby/object:Gem::Version
54
65
  version: '0'
55
- type: :runtime
66
+ type: :development
56
67
  prerelease: false
57
- version_requirements: *2157614020
68
+ version_requirements: *2152382540
58
69
  description: Bitemporal versioning for sequel, fully tested.
59
70
  email:
60
71
  - joseph.halter@thetalentbox.com
@@ -63,6 +74,7 @@ extensions: []
63
74
  extra_rdoc_files: []
64
75
  files:
65
76
  - .gitignore
77
+ - .travis.yml
66
78
  - Gemfile
67
79
  - README.md
68
80
  - Rakefile
@@ -85,15 +97,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
85
97
  - - ! '>='
86
98
  - !ruby/object:Gem::Version
87
99
  version: '0'
100
+ segments:
101
+ - 0
102
+ hash: -617172649856506715
88
103
  required_rubygems_version: !ruby/object:Gem::Requirement
89
104
  none: false
90
105
  requirements:
91
106
  - - ! '>='
92
107
  - !ruby/object:Gem::Version
93
108
  version: '0'
109
+ segments:
110
+ - 0
111
+ hash: -617172649856506715
94
112
  requirements: []
95
113
  rubyforge_project:
96
- rubygems_version: 1.8.6
114
+ rubygems_version: 1.8.10
97
115
  signing_key:
98
116
  specification_version: 3
99
117
  summary: Bitemporal versioning for sequel.