factbase 0.0.8 → 0.0.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/factbase.gemspec +1 -1
- data/lib/factbase/fact.rb +5 -3
- data/lib/factbase/query.rb +0 -10
- data/lib/factbase/syntax.rb +3 -0
- data/test/factbase/test_syntax.rb +1 -0
- data/test/factbase/test_term.rb +4 -2
- data/test/test_factbase.rb +1 -1
- 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: 38ebbf43ee181a50bc4ca45d32ac3ba1394180e25ea719b41917606c2d00a6c9
|
4
|
+
data.tar.gz: f2e71d19bd3523a4db543b410989f88708e3120cbebde21682080b822e11c7d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 802e11490eda7455f3d00ecce17c70e73f6520c5f06a25ea1ad7393ceb98a8ca67858343d4ee544183f10b695c872f140855037f091623ba057296c755fe6c13
|
7
|
+
data.tar.gz: d58f72e6aeabd5e99fe7424c769f56074c2f9dc95593dd76c3373ee770dcfd96c1f05dd51731c25660bfcb2aedfde2ffe8f7842679e6e46ef95532b090c3428c
|
data/factbase.gemspec
CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |s|
|
|
26
26
|
s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
|
27
27
|
s.required_ruby_version = '>=2.3'
|
28
28
|
s.name = 'factbase'
|
29
|
-
s.version = '0.0.
|
29
|
+
s.version = '0.0.9'
|
30
30
|
s.license = 'MIT'
|
31
31
|
s.summary = 'Factbase'
|
32
32
|
s.description = 'Fact base in memory and on disc'
|
data/lib/factbase/fact.rb
CHANGED
@@ -42,15 +42,17 @@ class Factbase::Fact
|
|
42
42
|
if k.end_with?('=')
|
43
43
|
kk = k[0..-2]
|
44
44
|
raise "Invalid prop name '#{kk}'" unless kk.match?(/^[a-z][a-zA-Z0-9]+$/)
|
45
|
+
v = args[1]
|
46
|
+
raise "Prop value can't be empty" if v == ''
|
45
47
|
@mutex.synchronize do
|
46
48
|
before = @map[kk]
|
47
|
-
return if before ==
|
49
|
+
return if before == v
|
48
50
|
if before.nil?
|
49
|
-
@map[kk] =
|
51
|
+
@map[kk] = v
|
50
52
|
return
|
51
53
|
end
|
52
54
|
@map[kk] = [@map[kk]] unless @map[kk].is_a?(Array)
|
53
|
-
@map[kk] <<
|
55
|
+
@map[kk] << v
|
54
56
|
end
|
55
57
|
nil
|
56
58
|
elsif k == '[]'
|
data/lib/factbase/query.rb
CHANGED
@@ -45,14 +45,4 @@ class Factbase::Query
|
|
45
45
|
yield f
|
46
46
|
end
|
47
47
|
end
|
48
|
-
|
49
|
-
# Turn it into an array.
|
50
|
-
# @return [Array] All facts in an array
|
51
|
-
# rubocop:disable Style/MapIntoArray
|
52
|
-
def to_a
|
53
|
-
array = []
|
54
|
-
each { |f| array << f }
|
55
|
-
array
|
56
|
-
end
|
57
|
-
# rubocop:enable Style/MapIntoArray
|
58
48
|
end
|
data/lib/factbase/syntax.rb
CHANGED
@@ -20,6 +20,7 @@
|
|
20
20
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
21
|
# SOFTWARE.
|
22
22
|
|
23
|
+
require_relative '../factbase'
|
23
24
|
require_relative 'fact'
|
24
25
|
require_relative 'term'
|
25
26
|
|
@@ -72,6 +73,7 @@ class Factbase::Syntax
|
|
72
73
|
[Factbase::Term.new(op, operands), at + 1]
|
73
74
|
end
|
74
75
|
|
76
|
+
# Turns a query into an array of tokens.
|
75
77
|
def to_tokens
|
76
78
|
list = []
|
77
79
|
acc = ''
|
@@ -108,6 +110,7 @@ class Factbase::Syntax
|
|
108
110
|
if t.is_a?(Symbol)
|
109
111
|
t
|
110
112
|
elsif t.start_with?('\'', '"')
|
113
|
+
raise 'String literal can\'t be empty' if t.length <= 2
|
111
114
|
t[1..-2]
|
112
115
|
elsif t.match?(/^[0-9]+$/)
|
113
116
|
t.to_i
|
data/test/factbase/test_term.rb
CHANGED
@@ -31,14 +31,16 @@ class TestTerm < Minitest::Test
|
|
31
31
|
def test_simple_matching
|
32
32
|
t = Factbase::Term.new(:eq, ['foo', 42])
|
33
33
|
assert(t.matches?(fact('foo' => [42])))
|
34
|
-
assert(!t.matches?(fact('foo' =>
|
34
|
+
assert(!t.matches?(fact('foo' => 'Hello!')))
|
35
35
|
assert(!t.matches?(fact('bar' => ['Hello!'])))
|
36
36
|
end
|
37
37
|
|
38
38
|
def test_eq_matching
|
39
39
|
t = Factbase::Term.new(:eq, ['foo', 42])
|
40
|
+
assert(t.matches?(fact('foo' => 42)))
|
40
41
|
assert(t.matches?(fact('foo' => [10, 5, 6, -8, 'hey', 42, 9, 'fdsf'])))
|
41
42
|
assert(!t.matches?(fact('foo' => [100])))
|
43
|
+
assert(!t.matches?(fact('foo' => [])))
|
42
44
|
end
|
43
45
|
|
44
46
|
def test_lt_matching
|
@@ -61,7 +63,7 @@ class TestTerm < Minitest::Test
|
|
61
63
|
def test_not_exists_matching
|
62
64
|
t = Factbase::Term.new(:not, [Factbase::Term.new(:eq, ['foo', 100])])
|
63
65
|
assert(t.matches?(fact('foo' => [42, 12, -90])))
|
64
|
-
assert(!t.matches?(fact('foo' =>
|
66
|
+
assert(!t.matches?(fact('foo' => 100)))
|
65
67
|
end
|
66
68
|
|
67
69
|
def test_or_matching
|
data/test/test_factbase.rb
CHANGED
@@ -54,7 +54,7 @@ class TestFactbase < Minitest::Test
|
|
54
54
|
File.write(f.path, f1.export)
|
55
55
|
f2.import(File.read(f.path))
|
56
56
|
end
|
57
|
-
assert_equal(1, f2.query('(eq foo 42)').to_a.count)
|
57
|
+
assert_equal(1, f2.query('(eq foo 42)').extend(Enumerable).to_a.count)
|
58
58
|
end
|
59
59
|
|
60
60
|
def test_to_json
|