factbase 0.0.21 → 0.0.22
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/factbase.gemspec +1 -1
- data/lib/factbase/looged.rb +1 -1
- data/lib/factbase/pre.rb +72 -0
- data/lib/factbase.rb +0 -2
- data/test/factbase/test_looged.rb +4 -5
- data/test/factbase/test_pre.rb +37 -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
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.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,8 +72,7 @@ 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
|
-
'Inserted fact #2',
|
75
|
+
'Inserted new fact',
|
77
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))\''
|
@@ -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/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
|