factbase 0.9.8 → 0.9.9
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/fixtures/stories/empty.yml +2 -0
- data/lib/factbase/query.rb +1 -1
- data/lib/factbase/tee.rb +1 -2
- data/lib/factbase.rb +1 -1
- data/test/factbase/indexed/test_indexed_query.rb +18 -0
- data/test/factbase/test_query.rb +6 -3
- data/test/factbase/test_tee.rb +7 -0
- 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: 72ae2c1184dfd8ab966591846cd054c3155b0536d8c7f2f7acf636df1eb7e045
|
4
|
+
data.tar.gz: fcf929766bf80cc040744ce9caa719503548fac719d956f676e9604374d78b8c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d6c3b87fd94afe4fc7984ca17be09ffd6dbff5d93951e264720201e2e5680e387fc0215331af563af7cc78ac3db9e199ca8a0aadc39d989fb377b975d3e1b8d
|
7
|
+
data.tar.gz: 26c9ffe593d79fc17d80949208cc0833d4147684a0fcd221dc6abd669c545da678dc4fd52723913bc29a68662ca43cf7470a9523022d0919af6dd42a440d69ca
|
data/fixtures/stories/empty.yml
CHANGED
data/lib/factbase/query.rb
CHANGED
@@ -44,7 +44,7 @@ class Factbase::Query
|
|
44
44
|
return to_enum(__method__, fb, params) unless block_given?
|
45
45
|
yielded = 0
|
46
46
|
params = params.transform_keys(&:to_s) if params.is_a?(Hash)
|
47
|
-
maybe = @term.predict(@maps, params)
|
47
|
+
maybe = @term.predict(@maps, Factbase::Tee.new({}, params))
|
48
48
|
(maybe || @maps).each do |m|
|
49
49
|
extras = {}
|
50
50
|
f = Factbase::Fact.new(m)
|
data/lib/factbase/tee.rb
CHANGED
@@ -35,11 +35,10 @@ class Factbase::Tee
|
|
35
35
|
n = args[1].to_s
|
36
36
|
n = n[1..] unless @upper.is_a?(Factbase::Tee)
|
37
37
|
r = @upper[n]
|
38
|
-
r = @fact[n] if r.nil?
|
39
38
|
r = [r] unless r.respond_to?(:each) || r.nil?
|
40
39
|
r
|
41
40
|
else
|
42
|
-
@fact.
|
41
|
+
@fact.send(*args)
|
43
42
|
end
|
44
43
|
end
|
45
44
|
end
|
data/lib/factbase.rb
CHANGED
@@ -82,7 +82,7 @@ require 'yaml'
|
|
82
82
|
# License:: MIT
|
83
83
|
class Factbase
|
84
84
|
# Current version of the gem (changed by .rultor.yml on every release)
|
85
|
-
VERSION = '0.9.
|
85
|
+
VERSION = '0.9.9' unless const_defined?(:VERSION)
|
86
86
|
|
87
87
|
# An exception that may be thrown in a transaction, to roll it back.
|
88
88
|
class Rollback < StandardError; end
|
@@ -40,6 +40,15 @@ class TestIndexedQuery < Factbase::Test
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
+
def test_fills_up_the_index
|
44
|
+
idx = {}
|
45
|
+
fb = Factbase::IndexedFactbase.new(Factbase.new, idx)
|
46
|
+
fb.query('(eq x 1)').each.to_a
|
47
|
+
assert_equal(1, idx.size)
|
48
|
+
fb.insert
|
49
|
+
assert_empty(idx)
|
50
|
+
end
|
51
|
+
|
43
52
|
def test_finds_by_eq_with_symbol
|
44
53
|
fb = Factbase::IndexedFactbase.new(Factbase.new)
|
45
54
|
f = fb.insert
|
@@ -159,6 +168,15 @@ class TestIndexedQuery < Factbase::Test
|
|
159
168
|
end
|
160
169
|
end
|
161
170
|
|
171
|
+
def test_joins_simple_one
|
172
|
+
idx = {}
|
173
|
+
fb = Factbase::IndexedFactbase.new(Factbase.new, idx)
|
174
|
+
fb.insert.who = 4
|
175
|
+
fb.insert.friend = 4
|
176
|
+
assert_equal(1, fb.query('(and (exists who) (join "f<=friend" (eq friend $who)))').each.to_a.size)
|
177
|
+
assert_equal(2, idx.size)
|
178
|
+
end
|
179
|
+
|
162
180
|
def test_joins_too
|
163
181
|
fb = Factbase::IndexedFactbase.new(Factbase.new)
|
164
182
|
total = 10_000
|
data/test/factbase/test_query.rb
CHANGED
@@ -116,7 +116,10 @@ class TestQuery < Factbase::Test
|
|
116
116
|
"(and (exists time) (not (\t\texists pi)))" => 1,
|
117
117
|
'(undef something)' => 3,
|
118
118
|
"(or (eq num +66) (lt time #{(Time.now - 200).utc.iso8601}))" => 1,
|
119
|
-
'(eq 3 (agg (eq num $num) (count)))' => 1
|
119
|
+
'(eq 3 (agg (eq num $num) (count)))' => 1,
|
120
|
+
'(and (eq num 42) (not (empty (eq name "Jeff"))))' => 2,
|
121
|
+
'(and (eq num 42) (empty (eq x $name)))' => 2,
|
122
|
+
'(and (eq num 42) (not (empty (eq name $name))))' => 2
|
120
123
|
}
|
121
124
|
maps = [
|
122
125
|
{ 'num' => [42], 'name' => ['Jeff'] },
|
@@ -197,9 +200,9 @@ class TestQuery < Factbase::Test
|
|
197
200
|
def test_finds_with_subsitution
|
198
201
|
maps = [{ 'foo' => [42] }, { 'bar' => [7] }, { 'foo' => [666] }]
|
199
202
|
with_factbases(maps) do |badge, fb|
|
200
|
-
assert_equal(
|
203
|
+
assert_equal(0, fb.query('(eq 2 (agg (eq foo $foo) (count)))').each.to_a.size, "with #{badge}")
|
201
204
|
fb.txn do |fbt|
|
202
|
-
assert_equal(
|
205
|
+
assert_equal(0, fbt.query('(eq 2 (agg (eq foo $foo) (count)))').each.to_a.size, "with #{badge} (txn)")
|
203
206
|
end
|
204
207
|
end
|
205
208
|
end
|
data/test/factbase/test_tee.rb
CHANGED
@@ -23,6 +23,13 @@ class TestTee < Factbase::Test
|
|
23
23
|
assert_equal([13], t['$bar'])
|
24
24
|
end
|
25
25
|
|
26
|
+
def test_no_trip_to_prim_if_not_found
|
27
|
+
prim = Factbase::Fact.new({})
|
28
|
+
prim.foo = 777
|
29
|
+
t = Factbase::Tee.new(prim, Factbase::Fact.new({}))
|
30
|
+
assert_nil(t['$foo'])
|
31
|
+
end
|
32
|
+
|
26
33
|
def test_all_properties
|
27
34
|
prim = Factbase::Fact.new({})
|
28
35
|
prim.foo = 42
|