factbase 0.0.8 → 0.0.10

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: eb59210ccd84c6ea917eddcc142535615c2ff1e08e3a1dcf2e1236de4e2e5c24
4
+ data.tar.gz: dc410950e07629cb29e3d5795508e8bf4504a983adb8887ba3f375d52f87d598
5
5
  SHA512:
6
- metadata.gz: 52582171bb9e9fa4be1d2c0670e3faa38de883675eb0db4a0efed94ad8d0d72437c8d1ce54d9e6442ecc4573ec68957cc99138d1a6b4580dfed7822397a863ca
7
- data.tar.gz: 857be193e43d1340f7c17c9d7230322e0bcd994c228f279a56731168eda36c463d68e8e3177b350f76f6bb70a27a1391e25edf0bccc905333e1502b361423467
6
+ metadata.gz: 81a0cfd3732fbd9ae30e867a0633cd1497c3df52a84461c4cbadaeca44414226c4c5be727b54823d1ee7dd5ee51e1a7397b1e0d3ddbee59339c013cf5493b603
7
+ data.tar.gz: 35e0e6d12f83c995e05bfc3ab4709dfe0476a5e8f36b2c772ff97b13477fc8210638259408dc9cee2e2aa86e499fc8a773d7ce63adcb0443c99ff56b2d04f9c0
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.10'
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
@@ -41,16 +41,18 @@ class Factbase::Fact
41
41
  k = args[0].to_s
42
42
  if k.end_with?('=')
43
43
  kk = k[0..-2]
44
- raise "Invalid prop name '#{kk}'" unless kk.match?(/^[a-z][a-zA-Z0-9]+$/)
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
data/lib/factbase.rb CHANGED
@@ -101,13 +101,13 @@ class Factbase
101
101
  xml.f do
102
102
  m.each do |k, vv|
103
103
  if vv.is_a?(Array)
104
- xml.send(:"#{k}") do
104
+ xml.send(:"#{k}_") do
105
105
  vv.each do |v|
106
106
  xml.send(:v, v)
107
107
  end
108
108
  end
109
109
  else
110
- xml.send(:"#{k}", vv)
110
+ xml.send(:"#{k}_", vv)
111
111
  end
112
112
  end
113
113
  end
@@ -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
@@ -71,12 +71,24 @@ class TestFactbase < Minitest::Test
71
71
  f = fb.insert
72
72
  f.foo = 42
73
73
  f.foo = 256
74
- fb.insert
74
+ fb.insert.bar = 5
75
75
  xml = Nokogiri::XML.parse(fb.to_xml)
76
76
  assert(!xml.xpath('/fb[count(f) = 2]').empty?)
77
77
  assert(!xml.xpath('/fb/f/foo[v="42"]').empty?)
78
78
  end
79
79
 
80
+ def test_to_xml_with_short_names
81
+ fb = Factbase.new
82
+ f = fb.insert
83
+ f.type = 1
84
+ f.f = 2
85
+ f.class = 3
86
+ xml = Nokogiri::XML.parse(fb.to_xml)
87
+ assert(!xml.xpath('/fb/f/type').empty?)
88
+ assert(!xml.xpath('/fb/f/f').empty?)
89
+ assert(!xml.xpath('/fb/f/class').empty?)
90
+ end
91
+
80
92
  def test_to_yaml
81
93
  fb = Factbase.new
82
94
  f = fb.insert
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.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko