factbase 0.0.20 → 0.0.22
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 +2 -2
- data/lib/factbase/pre.rb +72 -0
- data/lib/factbase/term.rb +4 -1
- data/lib/factbase.rb +0 -2
- data/test/factbase/test_looged.rb +5 -6
- data/test/factbase/test_pre.rb +37 -0
- data/test/factbase/test_query.rb +9 -0
- data/test/factbase/test_term.rb +7 -0
- data/test/test_factbase.rb +4 -5
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f66d5d5358e584ad5c4f73d551ceb03d8627c7a8ebfeea75c4bfbdcd08479b9
|
4
|
+
data.tar.gz: 047d233242c56b0788b66d7eef912d4aed78706b7afe321b60fcf3daf32e0026
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9749e3caf13ba363f5b76e598d007ccd731730579bc10851e29923f7304191eabf662ed0fd79864f02752f4ac5acd76537c7bbc352a97321e8aae13b1a94c0a
|
7
|
+
data.tar.gz: aa4a1cbe3bed556c478219fccdb3580925697cffa9dec838ed20f5f66b78006407a0ca3ff28e9dcc8adaa61f107b4566101401e99e3131bdbeb053f69505c910
|
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.22'
|
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
@@ -42,7 +42,7 @@ class Factbase::Looged
|
|
42
42
|
|
43
43
|
def insert
|
44
44
|
f = @fb.insert
|
45
|
-
@loog.debug(
|
45
|
+
@loog.debug('Inserted new fact')
|
46
46
|
Fact.new(f, @loog)
|
47
47
|
end
|
48
48
|
|
@@ -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
|
|
data/lib/factbase/pre.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (c) 2024 Yegor Bugayenko
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in all
|
13
|
+
# copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
# SOFTWARE.
|
22
|
+
|
23
|
+
require 'loog'
|
24
|
+
|
25
|
+
# A decorator of a Factbase, that runs a provided block on every +insert+.
|
26
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
27
|
+
# Copyright:: Copyright (c) 2024 Yegor Bugayenko
|
28
|
+
# License:: MIT
|
29
|
+
class Factbase::Pre
|
30
|
+
def initialize(fb, &block)
|
31
|
+
@fb = fb
|
32
|
+
@block = block
|
33
|
+
end
|
34
|
+
|
35
|
+
def empty?
|
36
|
+
@fb.empty?
|
37
|
+
end
|
38
|
+
|
39
|
+
def size
|
40
|
+
@fb.size
|
41
|
+
end
|
42
|
+
|
43
|
+
def insert
|
44
|
+
f = @fb.insert
|
45
|
+
@block.call(f)
|
46
|
+
f
|
47
|
+
end
|
48
|
+
|
49
|
+
def query(query)
|
50
|
+
@fb.query(query)
|
51
|
+
end
|
52
|
+
|
53
|
+
def export
|
54
|
+
@fb.export
|
55
|
+
end
|
56
|
+
|
57
|
+
def import(bytes)
|
58
|
+
@fb.import(bytes)
|
59
|
+
end
|
60
|
+
|
61
|
+
def to_json(opt = nil)
|
62
|
+
@fb.to_json(opt)
|
63
|
+
end
|
64
|
+
|
65
|
+
def to_xml
|
66
|
+
@fb.to_xml
|
67
|
+
end
|
68
|
+
|
69
|
+
def to_yaml
|
70
|
+
@fb.to_yaml
|
71
|
+
end
|
72
|
+
end
|
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)
|
data/lib/factbase.rb
CHANGED
@@ -34,13 +34,13 @@ class TestLooged < Minitest::Test
|
|
34
34
|
fb.insert
|
35
35
|
fb.insert.bar = 3
|
36
36
|
found = 0
|
37
|
-
fb.query('(exists
|
38
|
-
assert(42, f.
|
37
|
+
fb.query('(exists bar)').each do |f|
|
38
|
+
assert(42, f.bar.positive?)
|
39
39
|
f.foo = 42
|
40
40
|
assert_equal(42, f.foo)
|
41
41
|
found += 1
|
42
42
|
end
|
43
|
-
assert_equal(
|
43
|
+
assert_equal(1, found)
|
44
44
|
assert_equal(2, fb.size)
|
45
45
|
end
|
46
46
|
|
@@ -72,9 +72,8 @@ class TestLooged < Minitest::Test
|
|
72
72
|
fb.query('(exists bar)').each(&:to_s)
|
73
73
|
fb.query('(not (exists bar))').delete!
|
74
74
|
[
|
75
|
-
'Inserted fact
|
76
|
-
'
|
77
|
-
'Set \'bar\' to \'"3"\' (Integer)',
|
75
|
+
'Inserted new fact',
|
76
|
+
'Set \'bar\' to "3" (Integer)',
|
78
77
|
'Found 1 fact(s) by \'(exists bar)\'',
|
79
78
|
'Deleted 2 fact(s) by \'(not (exists bar))\''
|
80
79
|
].each do |s|
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (c) 2024 Yegor Bugayenko
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in all
|
13
|
+
# copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
# SOFTWARE.
|
22
|
+
|
23
|
+
require 'minitest/autorun'
|
24
|
+
require 'loog'
|
25
|
+
require_relative '../../lib/factbase/pre'
|
26
|
+
|
27
|
+
# Test.
|
28
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
29
|
+
# Copyright:: Copyright (c) 2024 Yegor Bugayenko
|
30
|
+
# License:: MIT
|
31
|
+
class TestPre < Minitest::Test
|
32
|
+
def test_simple_setting
|
33
|
+
fb = Factbase::Pre.new(Factbase.new) { |f| f.foo = 42 }
|
34
|
+
f = fb.insert
|
35
|
+
assert_equal(42, f.foo)
|
36
|
+
end
|
37
|
+
end
|
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])))
|
data/test/test_factbase.rb
CHANGED
@@ -34,15 +34,15 @@ class TestFactbase < Minitest::Test
|
|
34
34
|
def test_simple_setting
|
35
35
|
fb = Factbase.new
|
36
36
|
fb.insert
|
37
|
-
fb.insert
|
37
|
+
fb.insert.bar = 88
|
38
38
|
found = 0
|
39
|
-
fb.query('(exists
|
40
|
-
assert(42, f.
|
39
|
+
fb.query('(exists bar)').each do |f|
|
40
|
+
assert(42, f.bar.positive?)
|
41
41
|
f.foo = 42
|
42
42
|
assert_equal(42, f.foo)
|
43
43
|
found += 1
|
44
44
|
end
|
45
|
-
assert_equal(
|
45
|
+
assert_equal(1, found)
|
46
46
|
assert_equal(2, fb.size)
|
47
47
|
end
|
48
48
|
|
@@ -106,6 +106,5 @@ class TestFactbase < Minitest::Test
|
|
106
106
|
assert_equal(2, yaml['facts'].size)
|
107
107
|
assert_equal(42, yaml['facts'][0]['foo'][0])
|
108
108
|
assert_equal(256, yaml['facts'][0]['foo'][1])
|
109
|
-
assert_equal(2, yaml['facts'][1]['id'])
|
110
109
|
end
|
111
110
|
end
|
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.
|
4
|
+
version: 0.0.22
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yegor Bugayenko
|
@@ -97,6 +97,7 @@ files:
|
|
97
97
|
- lib/factbase.rb
|
98
98
|
- lib/factbase/fact.rb
|
99
99
|
- lib/factbase/looged.rb
|
100
|
+
- lib/factbase/pre.rb
|
100
101
|
- lib/factbase/query.rb
|
101
102
|
- lib/factbase/spy.rb
|
102
103
|
- lib/factbase/syntax.rb
|
@@ -105,6 +106,7 @@ files:
|
|
105
106
|
- renovate.json
|
106
107
|
- test/factbase/test_fact.rb
|
107
108
|
- test/factbase/test_looged.rb
|
109
|
+
- test/factbase/test_pre.rb
|
108
110
|
- test/factbase/test_query.rb
|
109
111
|
- test/factbase/test_spy.rb
|
110
112
|
- test/factbase/test_syntax.rb
|