factbase 0.7.1 → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/factbase/taped.rb +4 -0
- data/lib/factbase.rb +1 -1
- data/test/factbase/test_query.rb +30 -23
- data/test/test_factbase.rb +10 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e04b831fdaead7a6a84de7055d9d9bb47f052f6d0c00cb16d081d0074724cea3
|
4
|
+
data.tar.gz: e21055583e34664893d25fdfc9e928fed079dd014dc91cd1a2e0832d36301161
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c62a1fbc9f14bab4a66056a59e911c72b47dbc368deb29cc6e07d010b4f3c5c57d3ee9f881cc2c1292d1771202bd9da9c7a1fdfde3da79134848c14195d2f9d2
|
7
|
+
data.tar.gz: 657cba190035d6937a37da2446600b071c72b0f84dd468a89e1c429258c6e30ddd51bc0f086ea701afd3a8120fc857902f37a0af6e3dda36abf2b1a99ca03798
|
data/lib/factbase/taped.rb
CHANGED
data/lib/factbase.rb
CHANGED
@@ -64,7 +64,7 @@ require 'yaml'
|
|
64
64
|
# License:: MIT
|
65
65
|
class Factbase
|
66
66
|
# Current version of the gem (changed by .rultor.yml on every release)
|
67
|
-
VERSION = '0.7.
|
67
|
+
VERSION = '0.7.2'
|
68
68
|
|
69
69
|
# An exception that may be thrown in a transaction, to roll it back.
|
70
70
|
class Rollback < StandardError; end
|
data/test/factbase/test_query.rb
CHANGED
@@ -26,10 +26,11 @@ class TestQuery < Minitest::Test
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def test_complex_parsing
|
29
|
-
maps = [
|
30
|
-
|
31
|
-
|
32
|
-
|
29
|
+
maps = [
|
30
|
+
{ 'num' => [42], 'name' => ['Jeff'] },
|
31
|
+
{ 'pi' => [3.14], 'num' => [42, 66, 0], 'name' => ['peter'] },
|
32
|
+
{ 'time' => [Time.now - 100], 'num' => [0], 'hi' => [4], 'nome' => ['Walter'] }
|
33
|
+
]
|
33
34
|
{
|
34
35
|
'(eq num 444)' => 0,
|
35
36
|
'(eq hi 4)' => 1,
|
@@ -71,7 +72,11 @@ class TestQuery < Minitest::Test
|
|
71
72
|
"(or (eq num +66) (lt time #{(Time.now - 200).utc.iso8601}))" => 1,
|
72
73
|
'(eq 3 (agg (eq num $num) (count)))' => 1
|
73
74
|
}.each do |q, r|
|
74
|
-
|
75
|
+
fb = Factbase.new(maps)
|
76
|
+
assert_equal(r, fb.query(q).each.to_a.size, q)
|
77
|
+
fb.txn do |fbt|
|
78
|
+
assert_equal(r, fbt.query(q).each.to_a.size, q)
|
79
|
+
end
|
75
80
|
end
|
76
81
|
end
|
77
82
|
|
@@ -84,19 +89,21 @@ class TestQuery < Minitest::Test
|
|
84
89
|
end
|
85
90
|
|
86
91
|
def test_simple_deleting
|
87
|
-
maps = [
|
88
|
-
|
89
|
-
|
90
|
-
|
92
|
+
maps = [
|
93
|
+
{ 'foo' => [42] },
|
94
|
+
{ 'bar' => [4, 5] },
|
95
|
+
{ 'bar' => [5] }
|
96
|
+
]
|
91
97
|
q = Factbase::Query.new(Factbase.new, maps, Mutex.new, '(eq bar 5)')
|
92
98
|
assert_equal(2, q.delete!)
|
93
99
|
assert_equal(1, maps.size)
|
94
100
|
end
|
95
101
|
|
96
102
|
def test_reading_one
|
97
|
-
maps = [
|
98
|
-
|
99
|
-
|
103
|
+
maps = [
|
104
|
+
{ 'foo' => [42] },
|
105
|
+
{ 'bar' => [4, 5] }
|
106
|
+
]
|
100
107
|
{
|
101
108
|
'(agg (exists foo) (first foo))' => [42],
|
102
109
|
'(agg (exists z) (first z))' => nil,
|
@@ -114,10 +121,11 @@ class TestQuery < Minitest::Test
|
|
114
121
|
end
|
115
122
|
|
116
123
|
def test_deleting_nothing
|
117
|
-
maps = [
|
118
|
-
|
119
|
-
|
120
|
-
|
124
|
+
maps = [
|
125
|
+
{ 'foo' => [42] },
|
126
|
+
{ 'bar' => [4, 5] },
|
127
|
+
{ 'bar' => [5] }
|
128
|
+
]
|
121
129
|
q = Factbase::Query.new(Factbase.new, maps, Mutex.new, '(never)')
|
122
130
|
assert_equal(0, q.delete!)
|
123
131
|
assert_equal(3, maps.size)
|
@@ -144,9 +152,10 @@ class TestQuery < Minitest::Test
|
|
144
152
|
end
|
145
153
|
|
146
154
|
def test_with_params
|
147
|
-
maps = [
|
148
|
-
|
149
|
-
|
155
|
+
maps = [
|
156
|
+
{ 'foo' => [42] },
|
157
|
+
{ 'foo' => [17] }
|
158
|
+
]
|
150
159
|
found = 0
|
151
160
|
Factbase::Query.new(Factbase.new, maps, Mutex.new, '(eq foo $bar)').each(bar: [42]) do
|
152
161
|
found += 1
|
@@ -157,14 +166,12 @@ class TestQuery < Minitest::Test
|
|
157
166
|
end
|
158
167
|
|
159
168
|
def test_with_nil_alias
|
160
|
-
maps = []
|
161
|
-
maps << { 'foo' => [42] }
|
169
|
+
maps = [{ 'foo' => [42] }]
|
162
170
|
assert_nil(Factbase::Query.new(Factbase.new, maps, Mutex.new, '(as bar (plus xxx 3))').each.to_a[0]['bar'])
|
163
171
|
end
|
164
172
|
|
165
173
|
def test_get_all_properties
|
166
|
-
maps = []
|
167
|
-
maps << { 'foo' => [42] }
|
174
|
+
maps = [{ 'foo' => [42] }]
|
168
175
|
f = Factbase::Query.new(Factbase.new, maps, Mutex.new, '(always)').each.to_a[0]
|
169
176
|
assert_includes(f.all_properties, 'foo')
|
170
177
|
end
|
data/test/test_factbase.rb
CHANGED
@@ -137,11 +137,12 @@ class TestFactbase < Minitest::Test
|
|
137
137
|
|
138
138
|
def test_deals_with_arrays_in_txn
|
139
139
|
fb = Factbase.new
|
140
|
-
|
141
|
-
|
142
|
-
|
140
|
+
n = fb.insert
|
141
|
+
n.foo = 1
|
142
|
+
n.foo = 2
|
143
143
|
fb.txn do |fbt|
|
144
|
-
|
144
|
+
f = fbt.query('(gt foo 0)').each.to_a.first
|
145
|
+
assert_equal(1, f.foo)
|
145
146
|
end
|
146
147
|
end
|
147
148
|
|
@@ -197,9 +198,13 @@ class TestFactbase < Minitest::Test
|
|
197
198
|
|
198
199
|
def test_txn_inside_query
|
199
200
|
fb = Factbase.new
|
200
|
-
fb.insert
|
201
|
+
fact = fb.insert
|
202
|
+
fact.foo = 42
|
203
|
+
fact.foo = 555
|
201
204
|
fb.query('(exists foo)').each do |f|
|
202
205
|
fb.txn do |fbt|
|
206
|
+
assert_equal(42, fb.query('(always)').each.to_a.first.foo)
|
207
|
+
assert_equal(42, fb.query('(always)').each.to_a.first['foo'].first)
|
203
208
|
fbt.insert.bar = 33
|
204
209
|
end
|
205
210
|
f.xyz = 1
|