sequel_bitemporal 0.4.13 → 0.4.14
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/sequel/plugins/bitemporal.rb +13 -11
- data/sequel_bitemporal.gemspec +1 -1
- metadata +3 -3
@@ -1,3 +1,5 @@
|
|
1
|
+
require "date"
|
2
|
+
|
1
3
|
module Sequel
|
2
4
|
module Plugins
|
3
5
|
module Bitemporal
|
@@ -5,28 +7,28 @@ module Sequel
|
|
5
7
|
def self.as_we_knew_it(time)
|
6
8
|
previous = Thread.current[THREAD_POINT_IN_TIME_KEY]
|
7
9
|
raise ArgumentError, "requires a block" unless block_given?
|
8
|
-
Thread.current[THREAD_POINT_IN_TIME_KEY] = time.
|
10
|
+
Thread.current[THREAD_POINT_IN_TIME_KEY] = time.to_datetime
|
9
11
|
yield
|
10
12
|
ensure
|
11
13
|
Thread.current[THREAD_POINT_IN_TIME_KEY] = previous
|
12
14
|
end
|
13
15
|
|
14
16
|
def self.point_in_time
|
15
|
-
Thread.current[THREAD_POINT_IN_TIME_KEY] ||
|
17
|
+
Thread.current[THREAD_POINT_IN_TIME_KEY] || DateTime.now
|
16
18
|
end
|
17
19
|
|
18
20
|
THREAD_NOW_KEY = :sequel_plugins_bitemporal_now
|
19
21
|
def self.at(time)
|
20
22
|
previous = Thread.current[THREAD_NOW_KEY]
|
21
23
|
raise ArgumentError, "requires a block" unless block_given?
|
22
|
-
Thread.current[THREAD_NOW_KEY] = time.
|
24
|
+
Thread.current[THREAD_NOW_KEY] = time.to_datetime
|
23
25
|
yield
|
24
26
|
ensure
|
25
27
|
Thread.current[THREAD_NOW_KEY] = previous
|
26
28
|
end
|
27
29
|
|
28
30
|
def self.now
|
29
|
-
Thread.current[THREAD_NOW_KEY] ||
|
31
|
+
Thread.current[THREAD_NOW_KEY] || DateTime.now
|
30
32
|
end
|
31
33
|
|
32
34
|
def self.configure(master, opts = {})
|
@@ -76,14 +78,14 @@ module Sequel
|
|
76
78
|
t = ::Sequel::Plugins::Bitemporal.point_in_time
|
77
79
|
n = ::Sequel::Plugins::Bitemporal.now
|
78
80
|
!new? &&
|
79
|
-
created_at.
|
80
|
-
(expired_at.nil? || expired_at.
|
81
|
-
valid_from.
|
82
|
-
valid_to.
|
81
|
+
created_at.to_datetime<=t &&
|
82
|
+
(expired_at.nil? || expired_at.to_datetime>t) &&
|
83
|
+
valid_from.to_datetime<=n &&
|
84
|
+
valid_to.to_datetime>n
|
83
85
|
end
|
84
86
|
def destroy(opts={})
|
85
87
|
expand_previous_version = opts.fetch(:expand_previous_version){
|
86
|
-
valid_from.
|
88
|
+
valid_from.to_datetime>::Sequel::Plugins::Bitemporal.now
|
87
89
|
}
|
88
90
|
master.destroy_version self, expand_previous_version
|
89
91
|
end
|
@@ -184,10 +186,10 @@ module Sequel
|
|
184
186
|
def destroy_version(version, expand_previous_version)
|
185
187
|
now = ::Sequel::Plugins::Bitemporal.now
|
186
188
|
point_in_time = ::Sequel::Plugins::Bitemporal.point_in_time
|
187
|
-
return false if version.valid_to.
|
189
|
+
return false if version.valid_to.to_datetime<=now
|
188
190
|
model.db.transaction do
|
189
191
|
success = true
|
190
|
-
version_was_valid = now>=version.valid_from.
|
192
|
+
version_was_valid = now>=version.valid_from.to_datetime
|
191
193
|
if expand_previous_version
|
192
194
|
previous = versions_dataset.where({
|
193
195
|
expired_at: nil,
|
data/sequel_bitemporal.gemspec
CHANGED
@@ -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.4.
|
6
|
+
s.version = "0.4.14"
|
7
7
|
s.authors = ["Joseph HALTER", "Jonathan TRON"]
|
8
8
|
s.email = ["joseph.halter@thetalentbox.com", "jonathan.tron@thetalentbox.com"]
|
9
9
|
s.homepage = "https://github.com/TalentBox/sequel_bitemporal"
|
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.4.
|
4
|
+
version: 0.4.14
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -127,7 +127,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
127
127
|
version: '0'
|
128
128
|
segments:
|
129
129
|
- 0
|
130
|
-
hash:
|
130
|
+
hash: -1683115456060761780
|
131
131
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
132
|
none: false
|
133
133
|
requirements:
|
@@ -136,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
136
|
version: '0'
|
137
137
|
segments:
|
138
138
|
- 0
|
139
|
-
hash:
|
139
|
+
hash: -1683115456060761780
|
140
140
|
requirements: []
|
141
141
|
rubyforge_project:
|
142
142
|
rubygems_version: 1.8.24
|