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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1b9679d9fad6ba549ccccd428809c330ba6f2c3eefb3a8c32cd6b2ea9668f8e1
4
- data.tar.gz: 5103850e97643459fda4640e5564fe8073bc0c949b699a325a83360bb32e7dfc
3
+ metadata.gz: 72ae2c1184dfd8ab966591846cd054c3155b0536d8c7f2f7acf636df1eb7e045
4
+ data.tar.gz: fcf929766bf80cc040744ce9caa719503548fac719d956f676e9604374d78b8c
5
5
  SHA512:
6
- metadata.gz: cb9d62637fde56598cb1c2c01d492b6f2e0e9f144ee7eba1cbca88779be1214afc1f7ec43687baec3a9bc232ccb127856a9aad4b5732965667c2f69c91341229
7
- data.tar.gz: 10c1b8ddeeb23a0b1ed8de099aad0bf55c2e19370fba0d6686384a24769a57f3483cb10de5313588b0607e8dee9b4484050dde929b8e7fe2a9b053a96f242b20
6
+ metadata.gz: 0d6c3b87fd94afe4fc7984ca17be09ffd6dbff5d93951e264720201e2e5680e387fc0215331af563af7cc78ac3db9e199ca8a0aadc39d989fb377b975d3e1b8d
7
+ data.tar.gz: 26c9ffe593d79fc17d80949208cc0833d4147684a0fcd221dc6abd669c545da678dc4fd52723913bc29a68662ca43cf7470a9523022d0919af6dd42a440d69ca
@@ -19,3 +19,5 @@ queries:
19
19
  size: 3
20
20
  - query: (and (exists man) (empty (and (exists woman) (eq woman $wife))))
21
21
  size: 1
22
+ - query: (empty (eq woman $woman))
23
+ size: 4
@@ -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.method_missing(*args)
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.8' unless const_defined?(:VERSION)
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
@@ -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(1, fb.query('(eq 2 (agg (eq foo $foo) (count)))').each.to_a.size, "with #{badge}")
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(1, fbt.query('(eq 2 (agg (eq foo $foo) (count)))').each.to_a.size, "with #{badge} (txn)")
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
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: factbase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.8
4
+ version: 0.9.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko