factbase 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/factbase/accum.rb +1 -1
- data/lib/factbase/pre.rb +13 -2
- data/lib/factbase.rb +1 -1
- data/test/factbase/test_accum.rb +9 -0
- data/test/factbase/test_pre.rb +14 -0
- data/test/factbase/test_rules.rb +4 -1
- data/test/factbase/test_tee.rb +9 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a78379a3da6efaffa3672290e0ec7f38f2ec5b83032719388e07b517a4fb9e99
|
4
|
+
data.tar.gz: c172a777ddbb8e3799cf8e1fb55437a5172086724a8ed623ed08ff373ece7b87
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39ee04049fe211ef67de1eee8281ced0f6c2cba9eb132d80ab10c4d0d6dc3c22dde24675a1ee5810cf0b53be9c8f1e4e8afc622873537f44179cd9251fccff9e
|
7
|
+
data.tar.gz: 62390b4ef6e29ead3174f6b6a6d68d72e69cf2a35d667faf6c5aff05f310f1e42360da6917798f999a411e37894863b3956babf849d837fbc3ec4ced9306510d
|
data/lib/factbase/accum.rb
CHANGED
data/lib/factbase/pre.rb
CHANGED
@@ -24,7 +24,18 @@ require 'loog'
|
|
24
24
|
require 'decoor'
|
25
25
|
require_relative '../factbase'
|
26
26
|
|
27
|
-
# A decorator of a Factbase
|
27
|
+
# A decorator of a +Factbase+, that runs a provided block on every +insert+.
|
28
|
+
#
|
29
|
+
# For example, you can use this decorator if you want to put some properties
|
30
|
+
# into every fact that gets into the factbase:
|
31
|
+
#
|
32
|
+
# fb = Factbase::Pre.new(Factbase.new) do |f, fbt|
|
33
|
+
# f.when = Time.now
|
34
|
+
# end
|
35
|
+
#
|
36
|
+
# The second argument passed to the block is the factbase, while the first
|
37
|
+
# one is the fact just inserted.
|
38
|
+
#
|
28
39
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
29
40
|
# Copyright:: Copyright (c) 2024 Yegor Bugayenko
|
30
41
|
# License:: MIT
|
@@ -43,7 +54,7 @@ class Factbase::Pre
|
|
43
54
|
|
44
55
|
def insert
|
45
56
|
f = @fb.insert
|
46
|
-
@block.call(f)
|
57
|
+
@block.call(f, self)
|
47
58
|
f
|
48
59
|
end
|
49
60
|
|
data/lib/factbase.rb
CHANGED
@@ -81,7 +81,7 @@ require 'yaml'
|
|
81
81
|
# License:: MIT
|
82
82
|
class Factbase
|
83
83
|
# Current version of the gem (changed by .rultor.yml on every release)
|
84
|
-
VERSION = '0.
|
84
|
+
VERSION = '0.4.0'
|
85
85
|
|
86
86
|
# An exception that may be thrown in a transaction, to roll it back.
|
87
87
|
class Rollback < StandardError; end
|
data/test/factbase/test_accum.rb
CHANGED
@@ -67,4 +67,13 @@ class TestAccum < Minitest::Test
|
|
67
67
|
a = Factbase::Accum.new(f, {}, false)
|
68
68
|
assert(a['foo'].nil?)
|
69
69
|
end
|
70
|
+
|
71
|
+
def test_prints_to_string
|
72
|
+
map = {}
|
73
|
+
f = Factbase::Fact.new(Mutex.new, map)
|
74
|
+
props = {}
|
75
|
+
a = Factbase::Accum.new(f, props, true)
|
76
|
+
a.foo = 42
|
77
|
+
assert_equal('[ foo: [42] ]', f.to_s)
|
78
|
+
end
|
70
79
|
end
|
data/test/factbase/test_pre.rb
CHANGED
@@ -35,4 +35,18 @@ class TestPre < Minitest::Test
|
|
35
35
|
assert_equal(42, f.foo)
|
36
36
|
assert_equal(1, fb.query('(always)').each.to_a.size)
|
37
37
|
end
|
38
|
+
|
39
|
+
def test_in_transaction
|
40
|
+
fb =
|
41
|
+
Factbase::Pre.new(Factbase.new) do |f, fbt|
|
42
|
+
f.total = fbt.size
|
43
|
+
end
|
44
|
+
fb.txn do |fbt|
|
45
|
+
fbt.insert
|
46
|
+
fbt.insert
|
47
|
+
end
|
48
|
+
arr = fb.query('(always)').each.to_a
|
49
|
+
assert_equal(1, arr[0].total)
|
50
|
+
assert_equal(2, arr[1].total)
|
51
|
+
end
|
38
52
|
end
|
data/test/factbase/test_rules.rb
CHANGED
data/test/factbase/test_tee.rb
CHANGED
@@ -59,4 +59,13 @@ class TestTee < Minitest::Test
|
|
59
59
|
t = Factbase::Tee.new(prim, t)
|
60
60
|
assert_equal(7, t['$bar'])
|
61
61
|
end
|
62
|
+
|
63
|
+
def test_prints_to_string
|
64
|
+
prim = Factbase::Fact.new(Mutex.new, {})
|
65
|
+
prim.foo = 42
|
66
|
+
upper = Factbase::Fact.new(Mutex.new, {})
|
67
|
+
upper.bar = 13
|
68
|
+
t = Factbase::Tee.new(prim, upper)
|
69
|
+
assert_equal('[ foo: [42] ]', t.to_s)
|
70
|
+
end
|
62
71
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: factbase
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yegor Bugayenko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-08-
|
11
|
+
date: 2024-08-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: backtrace
|