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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cbdaf8e1b301fbb2aa6152156c36237f3a619861f100531baf422eceef38c376
4
- data.tar.gz: b41709f25cd6652fd2e51e4550a30b99f453c9965ff14026241c7d8a9c894352
3
+ metadata.gz: e04b831fdaead7a6a84de7055d9d9bb47f052f6d0c00cb16d081d0074724cea3
4
+ data.tar.gz: e21055583e34664893d25fdfc9e928fed079dd014dc91cd1a2e0832d36301161
5
5
  SHA512:
6
- metadata.gz: 8046597926096add3f76ac9e4741d1e34eac946ddf7189fa5b3df224fb4b345d010a08feb685725083c641d883d85d4e3bd11a4593c47d2722f44d58f46f3f8f
7
- data.tar.gz: e5a33af012a4392474e2d4bdf184a5dbc995e2fa95ed4bb270b0a2b0eddedc9630aa372a72404f0bd90996ac6aab03b278b2a791be898adf084ef1dbb4967cf0
6
+ metadata.gz: c62a1fbc9f14bab4a66056a59e911c72b47dbc368deb29cc6e07d010b4f3c5c57d3ee9f881cc2c1292d1771202bd9da9c7a1fdfde3da79134848c14195d2f9d2
7
+ data.tar.gz: 657cba190035d6937a37da2446600b071c72b0f84dd468a89e1c429258c6e30ddd51bc0f086ea701afd3a8120fc857902f37a0af6e3dda36abf2b1a99ca03798
@@ -91,6 +91,10 @@ class Factbase::Taped
91
91
  @origin.each(&)
92
92
  end
93
93
 
94
+ def [](key)
95
+ @origin[key]
96
+ end
97
+
94
98
  def to_a
95
99
  @origin.to_a
96
100
  end
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.1'
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
@@ -26,10 +26,11 @@ class TestQuery < Minitest::Test
26
26
  end
27
27
 
28
28
  def test_complex_parsing
29
- maps = []
30
- maps << { 'num' => [42], 'name' => ['Jeff'] }
31
- maps << { 'pi' => [3.14], 'num' => [42, 66, 0], 'name' => ['peter'] }
32
- maps << { 'time' => [Time.now - 100], 'num' => [0], 'hi' => [4], 'nome' => ['Walter'] }
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
- assert_equal(r, Factbase::Query.new(Factbase.new, maps, Mutex.new, q).each.to_a.size, q)
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
- maps << { 'foo' => [42] }
89
- maps << { 'bar' => [4, 5] }
90
- maps << { 'bar' => [5] }
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
- maps << { 'foo' => [42] }
99
- maps << { 'bar' => [4, 5] }
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
- maps << { 'foo' => [42] }
119
- maps << { 'bar' => [4, 5] }
120
- maps << { 'bar' => [5] }
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
- maps << { 'foo' => [42] }
149
- maps << { 'foo' => [17] }
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
@@ -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
- f = fb.insert
141
- f.foo = 1
142
- f.foo = 2
140
+ n = fb.insert
141
+ n.foo = 1
142
+ n.foo = 2
143
143
  fb.txn do |fbt|
144
- assert_equal(1, fbt.query('(gt foo 0)').each.to_a.size)
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.foo = 42
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
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.7.1
4
+ version: 0.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko