chrono_model 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/chrono_model/time_machine.rb +18 -1
- data/lib/chrono_model/version.rb +1 -1
- data/spec/time_machine_spec.rb +8 -2
- metadata +6 -6
@@ -147,11 +147,28 @@ module ChronoModel
|
|
147
147
|
end
|
148
148
|
|
149
149
|
# Returns a read-only representation of this record as it was +time+ ago.
|
150
|
+
# Returns nil if no record is found.
|
150
151
|
#
|
151
152
|
def as_of(time)
|
152
|
-
|
153
|
+
_as_of(time).first
|
153
154
|
end
|
154
155
|
|
156
|
+
# Returns a read-only representation of this record as it was +time+ ago.
|
157
|
+
# Raises ActiveRecord::RecordNotFound if no record is found.
|
158
|
+
#
|
159
|
+
def as_of!(time)
|
160
|
+
_as_of(time).first!
|
161
|
+
end
|
162
|
+
|
163
|
+
# Delegates to +HistoryMethods.as_of+ to fetch this instance as it was on
|
164
|
+
# +time+. Used both by +as_of+ and +as_of!+ for performance reasons, to
|
165
|
+
# avoid a `rescue` (@lleirborras).
|
166
|
+
#
|
167
|
+
def _as_of(time)
|
168
|
+
self.class.as_of(time).where(:id => self.id)
|
169
|
+
end
|
170
|
+
protected :_as_of
|
171
|
+
|
155
172
|
# Return the complete read-only history of this instance.
|
156
173
|
#
|
157
174
|
def history
|
data/lib/chrono_model/version.rb
CHANGED
data/spec/time_machine_spec.rb
CHANGED
@@ -94,8 +94,14 @@ describe ChronoModel::TimeMachine do
|
|
94
94
|
it { bar.as_of(bar.ts[3]).foo.name.should == 'new foo' }
|
95
95
|
end
|
96
96
|
|
97
|
-
it '
|
98
|
-
expect { foo.as_of(1.minute.ago) }.
|
97
|
+
it 'doesn\'t raise RecordNotFound when no history records are found' do
|
98
|
+
expect { foo.as_of(1.minute.ago) }.to_not raise_error
|
99
|
+
foo.as_of(1.minute.ago).should be_nil
|
100
|
+
end
|
101
|
+
|
102
|
+
|
103
|
+
it 'raises ActiveRecord::RecordNotFound in the bang variant' do
|
104
|
+
expect { foo.as_of!(1.minute.ago) }.to raise_error(ActiveRecord::RecordNotFound)
|
99
105
|
end
|
100
106
|
|
101
107
|
describe 'it honors default_scopes' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chrono_model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.2
|
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: 2013-
|
12
|
+
date: 2013-08-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
16
|
-
requirement: &
|
16
|
+
requirement: &84655320 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '3.2'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *84655320
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: pg
|
27
|
-
requirement: &
|
27
|
+
requirement: &84655110 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *84655110
|
36
36
|
description: Give your models as-of date temporal extensions. Built entirely for PostgreSQL
|
37
37
|
>= 9.0
|
38
38
|
email:
|