factbase 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4ff1dd0d8b331a0a2c90d6160e7e0594a186016338591d7fa3702b3fc7e29731
4
- data.tar.gz: f95d83697fb8fb2aceab49547850a27548858db76a36a7a90a582257174214f0
3
+ metadata.gz: 38ebbf43ee181a50bc4ca45d32ac3ba1394180e25ea719b41917606c2d00a6c9
4
+ data.tar.gz: f2e71d19bd3523a4db543b410989f88708e3120cbebde21682080b822e11c7d7
5
5
  SHA512:
6
- metadata.gz: 52582171bb9e9fa4be1d2c0670e3faa38de883675eb0db4a0efed94ad8d0d72437c8d1ce54d9e6442ecc4573ec68957cc99138d1a6b4580dfed7822397a863ca
7
- data.tar.gz: 857be193e43d1340f7c17c9d7230322e0bcd994c228f279a56731168eda36c463d68e8e3177b350f76f6bb70a27a1391e25edf0bccc905333e1502b361423467
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.8'
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 == args[1]
49
+ return if before == v
48
50
  if before.nil?
49
- @map[kk] = args[1]
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] << args[1]
55
+ @map[kk] << v
54
56
  end
55
57
  nil
56
58
  elsif k == '[]'
@@ -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
@@ -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
@@ -92,6 +92,7 @@ class TestSyntax < Minitest::Test
92
92
  '(foo x y z (',
93
93
  '(foo x y (z t (f 42 ',
94
94
  ')foo ) y z)',
95
+ '(x "")',
95
96
  ")y 42 'Hey you)",
96
97
  ')',
97
98
  '"'
@@ -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' => ['Hello!'])))
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' => [100])))
66
+ assert(!t.matches?(fact('foo' => 100)))
65
67
  end
66
68
 
67
69
  def test_or_matching
@@ -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
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.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko