factbase 0.0.19 → 0.0.21
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/looged.rb +23 -8
- data/lib/factbase/term.rb +4 -1
- data/test/factbase/test_looged.rb +13 -1
- data/test/factbase/test_query.rb +9 -0
- data/test/factbase/test_term.rb +7 -0
- 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: dd8e28cf7e8e84fc0364bb8780775592aa86c415a05a49d4edd88bbc9a717a80
|
4
|
+
data.tar.gz: ba7c821a3d229cb5f8b0e9fd1e632cd6d2e69c33eacb6b49751a5dd92902a23a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 897308019e1fb3e05bad6e47ac06c39ec91250981e1b0206600a9a5620cb03b29c9dac866640994ac077e6bc3c418b5ea8aec7878e1e2b4587bab6d77b2cffb7
|
7
|
+
data.tar.gz: 50172f65e3b8e40a30ec37155264c464b6a2849152ff9752270a38e8610c022506cd4b69cc1ed6869b2b8ecaa6056e3976d48a73642b067ffaedfc28ad887959
|
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.21'
|
30
30
|
s.license = 'MIT'
|
31
31
|
s.summary = 'Factbase'
|
32
32
|
s.description = 'Fact base in memory and on disc'
|
data/lib/factbase/looged.rb
CHANGED
@@ -85,7 +85,7 @@ class Factbase::Looged
|
|
85
85
|
r = @fact.method_missing(*args)
|
86
86
|
k = args[0].to_s
|
87
87
|
v = args[1]
|
88
|
-
@loog.debug("Set '#{k[0..-2]}' to
|
88
|
+
@loog.debug("Set '#{k[0..-2]}' to #{v.to_s.inspect} (#{v.class})") if k.end_with?('=')
|
89
89
|
r
|
90
90
|
end
|
91
91
|
|
@@ -109,19 +109,34 @@ class Factbase::Looged
|
|
109
109
|
end
|
110
110
|
|
111
111
|
def each(&)
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
112
|
+
if block_given?
|
113
|
+
r = @query.each(&)
|
114
|
+
raise ".each of #{@query.class} returned #{r.class}" unless r.is_a?(Integer)
|
115
|
+
if r.zero?
|
116
|
+
@loog.debug("Nothing found by '#{@expr}'")
|
117
|
+
else
|
118
|
+
@loog.debug("Found #{r} fact(s) by '#{@expr}'")
|
119
|
+
end
|
120
|
+
r
|
116
121
|
else
|
117
|
-
|
122
|
+
array = []
|
123
|
+
# rubocop:disable Style/MapIntoArray
|
124
|
+
@query.each do |f|
|
125
|
+
array << f
|
126
|
+
end
|
127
|
+
# rubocop:enable Style/MapIntoArray
|
128
|
+
if array.empty?
|
129
|
+
@loog.debug("Nothing found by '#{@expr}'")
|
130
|
+
else
|
131
|
+
@loog.debug("Found #{array.size} fact(s) by '#{@expr}'")
|
132
|
+
end
|
133
|
+
array
|
118
134
|
end
|
119
|
-
r
|
120
135
|
end
|
121
136
|
|
122
137
|
def delete!
|
123
138
|
r = @query.delete!
|
124
|
-
raise
|
139
|
+
raise ".delete! of #{@query.class} returned #{r.class}" unless r.is_a?(Integer)
|
125
140
|
if r.zero?
|
126
141
|
@loog.debug("Nothing deleted by '#{@expr}'")
|
127
142
|
else
|
data/lib/factbase/term.rb
CHANGED
@@ -124,7 +124,10 @@ class Factbase::Term
|
|
124
124
|
v = fact[k]
|
125
125
|
return false if v.nil?
|
126
126
|
v = [v] unless v.is_a?(Array)
|
127
|
-
v.any?
|
127
|
+
v.any? do |vv|
|
128
|
+
vv = vv.floor if vv.is_a?(Time) && op == :==
|
129
|
+
vv.send(op, @operands[1])
|
130
|
+
end
|
128
131
|
end
|
129
132
|
|
130
133
|
def assert_args(num)
|
@@ -51,6 +51,18 @@ class TestLooged < Minitest::Test
|
|
51
51
|
assert_equal(2, Factbase::Looged.new(fb, Loog::NULL).query('()').each(&:to_s))
|
52
52
|
end
|
53
53
|
|
54
|
+
def test_returns_int_when_empty
|
55
|
+
fb = Factbase.new
|
56
|
+
assert_equal(0, Factbase::Looged.new(fb, Loog::NULL).query('()').each(&:to_s))
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_logs_when_enumerator
|
60
|
+
fb = Factbase::Looged.new(Factbase.new, Loog::NULL)
|
61
|
+
assert_equal(0, fb.query('()').each.to_a.size)
|
62
|
+
fb.insert
|
63
|
+
assert_equal(1, fb.query('()').each.to_a.size)
|
64
|
+
end
|
65
|
+
|
54
66
|
def test_proper_logging
|
55
67
|
log = Loog::Buffer.new
|
56
68
|
fb = Factbase::Looged.new(Factbase.new, log)
|
@@ -62,7 +74,7 @@ class TestLooged < Minitest::Test
|
|
62
74
|
[
|
63
75
|
'Inserted fact #1',
|
64
76
|
'Inserted fact #2',
|
65
|
-
'Set \'bar\' to
|
77
|
+
'Set \'bar\' to "3" (Integer)',
|
66
78
|
'Found 1 fact(s) by \'(exists bar)\'',
|
67
79
|
'Deleted 2 fact(s) by \'(not (exists bar))\''
|
68
80
|
].each do |s|
|
data/test/factbase/test_query.rb
CHANGED
@@ -21,6 +21,7 @@
|
|
21
21
|
# SOFTWARE.
|
22
22
|
|
23
23
|
require 'minitest/autorun'
|
24
|
+
require 'time'
|
24
25
|
require_relative '../../lib/factbase'
|
25
26
|
require_relative '../../lib/factbase/query'
|
26
27
|
|
@@ -62,6 +63,14 @@ class TestQuery < Minitest::Test
|
|
62
63
|
end
|
63
64
|
end
|
64
65
|
|
66
|
+
def test_simple_parsing_with_time
|
67
|
+
maps = []
|
68
|
+
now = Time.now.utc
|
69
|
+
maps << { 'foo' => now }
|
70
|
+
q = Factbase::Query.new(maps, Mutex.new, "(eq foo #{now.iso8601})")
|
71
|
+
assert_equal(1, q.each.to_a.size)
|
72
|
+
end
|
73
|
+
|
65
74
|
def test_simple_deleting
|
66
75
|
maps = []
|
67
76
|
maps << { 'foo' => [42] }
|
data/test/factbase/test_term.rb
CHANGED
@@ -44,6 +44,13 @@ class TestTerm < Minitest::Test
|
|
44
44
|
assert(!t.matches?(fact('bar' => [])))
|
45
45
|
end
|
46
46
|
|
47
|
+
def test_eq_matching_time
|
48
|
+
now = Time.now
|
49
|
+
t = Factbase::Term.new(:eq, [:foo, Time.parse(now.iso8601)])
|
50
|
+
assert(t.matches?(fact('foo' => now)))
|
51
|
+
assert(t.matches?(fact('foo' => [now, Time.now])))
|
52
|
+
end
|
53
|
+
|
47
54
|
def test_lt_matching
|
48
55
|
t = Factbase::Term.new(:lt, [:foo, 42])
|
49
56
|
assert(t.matches?(fact('foo' => [10])))
|