factbase 0.9.4 → 0.9.5

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: 39eb84c924fd5a4c42a73f3a9cc077d3d48d2973d513602c81b7cebb2ed9c35f
4
- data.tar.gz: 9187cac9070ee7444a0849eef2a48ce78118840bc53c2e1e01f642924c69ea91
3
+ metadata.gz: '05496abcbec07a37de19ac7f1218943d1d50d1f0b3611ab48e6b8489675d274c'
4
+ data.tar.gz: b8f33d58069745e5405d6f1714c80f6fb3badc437333ce1fe685af5fb245bc42
5
5
  SHA512:
6
- metadata.gz: c27c52ab2a3c7e9e26b2964d6cecb504249d9d3be4ac1206367dbc885d9e7892671f89c37c681218818849189ccf672348b4478c7c93fa7117883e0e49cd63a4
7
- data.tar.gz: b1a7b747bf06380b76369e73bed096a7805f100872809b61f12d3dcf6bec60871e69a822da739b961b62c4d6d3542d68229a403522f24121cee2b8b93765e6c6
6
+ metadata.gz: 1475969fc18741368eff7ababc1ff5764f36244f3e11276d21a5d4f03f9d5c3ce444cf9ecd0482be3e9f3a3b3fadbc11cba5a711244dd26b39fc4be60a6915f9
7
+ data.tar.gz: 2e30a6d6cc39ada5038f98d8b6112250e527b756a0f9d5f5a8aebecd661d8de8e022d4d5659065ec0273035fbe740f5ea655b3f82e701993084a6755c96700f4
@@ -20,9 +20,9 @@ module Factbase::IndexedTerm
20
20
  # @param [Hash] params Key/value params to use
21
21
  # @return [Array<Hash>|nil] Returns a new array, or NIL if the original array must be used
22
22
  def predict(maps, params)
23
+ key = [maps.object_id, @operands.first, @op]
23
24
  case @op
24
25
  when :one
25
- key = [maps.object_id, @operands.first, @op]
26
26
  if @idx[key].nil?
27
27
  @idx[key] = []
28
28
  prop = @operands.first.to_s
@@ -32,7 +32,6 @@ module Factbase::IndexedTerm
32
32
  end
33
33
  (maps & []) | @idx[key]
34
34
  when :exists
35
- key = [maps.object_id, @operands.first, @op]
36
35
  if @idx[key].nil?
37
36
  @idx[key] = []
38
37
  prop = @operands.first.to_s
@@ -43,7 +42,6 @@ module Factbase::IndexedTerm
43
42
  (maps & []) | @idx[key]
44
43
  when :eq
45
44
  if @operands.first.is_a?(Symbol) && _scalar?(@operands[1])
46
- key = [maps.object_id, @operands.first, @op]
47
45
  if @idx[key].nil?
48
46
  @idx[key] = {}
49
47
  prop = @operands.first.to_s
@@ -79,7 +77,7 @@ module Factbase::IndexedTerm
79
77
  if r.nil?
80
78
  r = n
81
79
  else
82
- r &= n
80
+ r &= n.to_a
83
81
  end
84
82
  break if r.empty?
85
83
  end
@@ -93,7 +91,7 @@ module Factbase::IndexedTerm
93
91
  break
94
92
  end
95
93
  r = maps & [] if r.nil?
96
- r |= n
94
+ r |= n.to_a
97
95
  end
98
96
  r
99
97
  when :not
@@ -44,7 +44,8 @@ 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
- (@term.predict(@maps, params) || @maps).each do |m|
47
+ maybe = @term.predict(@maps, params)
48
+ (maybe || @maps).each do |m|
48
49
  extras = {}
49
50
  f = Factbase::Fact.new(m)
50
51
  f = Factbase::Tee.new(f, params)
@@ -73,6 +73,7 @@ class Factbase::Taped
73
73
  end
74
74
 
75
75
  def |(other)
76
+ return Factbase::Taped.new(to_a, inserted: @inserted, deleted: @deleted, added: @added) if other == []
76
77
  join(other, &:|)
77
78
  end
78
79
 
@@ -143,20 +144,13 @@ class Factbase::Taped
143
144
 
144
145
  def join(other)
145
146
  n = yield @origin.to_a, other.to_a
146
- if other.respond_to?(:inserted)
147
- Factbase::Taped.new(
148
- n,
149
- inserted: @inserted | other.inserted,
150
- deleted: @deleted | other.deleted,
151
- added: @added | other.added
152
- )
153
- else
154
- Factbase::Taped.new(
155
- n,
156
- inserted: @inserted,
157
- deleted: @deleted,
158
- added: @added
159
- )
160
- end
147
+ raise 'Cannot join with another Taped' if other.respond_to?(:inserted)
148
+ raise 'Can only join with array' unless other.is_a?(Array)
149
+ Factbase::Taped.new(
150
+ n,
151
+ inserted: @inserted,
152
+ deleted: @deleted,
153
+ added: @added
154
+ )
161
155
  end
162
156
  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.4' unless const_defined?(:VERSION)
85
+ VERSION = '0.9.5' 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
@@ -24,16 +24,33 @@ class TestIndexedFactbase < Factbase::Test
24
24
  end
25
25
 
26
26
  def test_queries_after_update_in_txn
27
- origin = Factbase.new
28
- fb = Factbase::IndexedFactbase.new(origin)
29
- fb.insert.foo = 42
30
- fb.txn do |fbt|
31
- fbt.query('(exists foo)').each do |f|
32
- f.bar = f.foo + 1
27
+ [
28
+ '(exists boom)',
29
+ '(one boom)',
30
+ '(and (exists boom) (exists boom))',
31
+ '(and (exists boom) (exists boom) (exists boom))',
32
+ '(and (one boom) (one boom))',
33
+ '(and (one boom) (one foo))',
34
+ '(and (one boom) (one boom) (one boom))',
35
+ '(and (one boom) (one boom) (one boom) (one foo))',
36
+ '(and (one boom) (exists boom))',
37
+ '(and (exists boom) (one boom) (one boom))',
38
+ '(and (exists boom) (exists boom) (one boom))',
39
+ '(and (eq foo 42) (exists boom) (one boom) (not (exists bar)))'
40
+ ].each do |q|
41
+ origin = Factbase.new
42
+ fb = Factbase::IndexedFactbase.new(origin)
43
+ f = fb.insert
44
+ f.foo = 42
45
+ f.boom = 33
46
+ fb.txn do |fbt|
47
+ fbt.query(q).each do |n|
48
+ n.bar = n.foo + 1
49
+ end
33
50
  end
51
+ refute_empty(origin.query('(exists bar)').each.to_a, q)
52
+ refute_empty(fb.query('(exists bar)').each.to_a, q)
34
53
  end
35
- refute_empty(origin.query('(exists bar)').each.to_a)
36
- refute_empty(fb.query('(exists bar)').each.to_a)
37
54
  end
38
55
 
39
56
  def test_queries_after_insert_in_txn
@@ -21,6 +21,7 @@ class TestIndexedTerm < Factbase::Test
21
21
  maps = Factbase::Taped.new([{ 'foo' => [42] }, { 'bar' => [7] }, { 'foo' => [22, 42] }, { 'foo' => [] }])
22
22
  n = term.predict(maps, { a: 1 })
23
23
  assert_equal(2, n.size)
24
+ assert_kind_of(Factbase::Taped, n)
24
25
  end
25
26
 
26
27
  def test_predicts_on_exists
@@ -30,6 +31,7 @@ class TestIndexedTerm < Factbase::Test
30
31
  maps = Factbase::Taped.new([{ 'foo' => [42] }, { 'bar' => [7] }, { 'foo' => [22, 42] }, { 'foo' => [] }])
31
32
  n = term.predict(maps, { a: 1 })
32
33
  assert_equal(3, n.size)
34
+ assert_kind_of(Factbase::Taped, n)
33
35
  end
34
36
 
35
37
  def test_predicts_on_one
@@ -39,6 +41,7 @@ class TestIndexedTerm < Factbase::Test
39
41
  maps = Factbase::Taped.new([{ 'foo' => [42] }, { 'bar' => [7] }, { 'foo' => [22, 42] }, { 'foo' => [] }])
40
42
  n = term.predict(maps, { a: 1 })
41
43
  assert_equal(1, n.size)
44
+ assert_kind_of(Factbase::Taped, n)
42
45
  end
43
46
 
44
47
  def test_predicts_on_not
@@ -48,6 +51,7 @@ class TestIndexedTerm < Factbase::Test
48
51
  maps = Factbase::Taped.new([{ 'foo' => [42] }, { 'bar' => [7], 'foo' => [22, 42] }, { 'foo' => [22] }])
49
52
  n = term.predict(maps, { a: 1 })
50
53
  assert_equal(1, n.size)
54
+ assert_kind_of(Factbase::Taped, n)
51
55
  end
52
56
 
53
57
  def test_predicts_on_and
@@ -63,6 +67,7 @@ class TestIndexedTerm < Factbase::Test
63
67
  maps = Factbase::Taped.new([{ 'foo' => [42] }, { 'bar' => [7], 'foo' => [22, 42] }, { 'foo' => [22, 42] }])
64
68
  n = term.predict(maps, { a: 1 })
65
69
  assert_equal(1, n.size)
70
+ assert_kind_of(Factbase::Taped, n)
66
71
  end
67
72
 
68
73
  def test_predicts_on_or
@@ -79,6 +84,7 @@ class TestIndexedTerm < Factbase::Test
79
84
  maps = Factbase::Taped.new([{ 'foo' => [42] }, { 'bar' => [7], 'foo' => [22, 42] }, { 'foo' => [22, 42] }])
80
85
  n = term.predict(maps, { a: 1 })
81
86
  assert_equal(3, n.size)
87
+ assert_kind_of(Factbase::Taped, n)
82
88
  end
83
89
 
84
90
  def test_predicts_on_others
@@ -238,7 +238,7 @@ class TestQuery < Factbase::Test
238
238
  fbt.query('(exists foo)').each do |f|
239
239
  f.bar = 33
240
240
  end
241
- refute_empty(fbt.query('(exists bar)').each.to_a)
241
+ refute_empty(fbt.query('(exists bar)').each.to_a, "in #{badge}")
242
242
  end
243
243
  refute_empty(fb.query('(exists bar)').each.to_a, "in #{badge}")
244
244
  assert_empty(fb.query('(and (exists foo) (not (exists bar)))').each.to_a, "in #{badge}")
@@ -315,7 +315,10 @@ class TestQuery < Factbase::Test
315
315
  Factbase::SyncFactbase.new(
316
316
  Factbase::CachedFactbase.new(
317
317
  Factbase::IndexedFactbase.new(
318
- Factbase.new(maps)
318
+ Factbase::Logged.new(
319
+ Factbase.new(maps),
320
+ Loog::NULL
321
+ )
319
322
  )
320
323
  )
321
324
  )
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: factbase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.4
4
+ version: 0.9.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-03-18 00:00:00.000000000 Z
10
+ date: 2025-03-19 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: backtrace