factbase 0.5.2 → 0.7.0
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/.0pdd.yml +2 -19
- data/.github/workflows/actionlint.yml +4 -20
- data/.github/workflows/benchmark.yml +10 -25
- data/.github/workflows/codecov.yml +6 -20
- data/.github/workflows/copyrights.yml +4 -19
- data/.github/workflows/markdown-lint.yml +4 -19
- data/.github/workflows/pdd.yml +4 -19
- data/.github/workflows/rake.yml +5 -21
- data/.github/workflows/reuse.yml +19 -0
- data/.github/workflows/xcop.yml +4 -19
- data/.github/workflows/yamllint.yml +4 -21
- data/.gitignore +1 -0
- data/.rubocop.yml +5 -21
- data/.rultor.yml +3 -19
- data/.simplecov +2 -19
- data/Gemfile +8 -24
- data/Gemfile.lock +40 -31
- data/LICENSES/MIT.txt +21 -0
- data/README.md +40 -10
- data/REUSE.toml +25 -0
- data/Rakefile +3 -28
- data/benchmarks/simple.rb +55 -24
- data/factbase.gemspec +2 -19
- data/lib/factbase/accum.rb +4 -21
- data/lib/factbase/churn.rb +44 -0
- data/lib/factbase/fact.rb +2 -19
- data/lib/factbase/flatten.rb +2 -19
- data/lib/factbase/inv.rb +6 -25
- data/lib/factbase/light.rb +32 -0
- data/lib/factbase/looged.rb +6 -27
- data/lib/factbase/pre.rb +6 -25
- data/lib/factbase/query.rb +4 -21
- data/lib/factbase/query_once.rb +2 -19
- data/lib/factbase/rules.rb +5 -26
- data/lib/factbase/syntax.rb +2 -19
- data/lib/factbase/tallied.rb +93 -0
- data/lib/factbase/taped.rb +113 -0
- data/lib/factbase/tee.rb +2 -19
- data/lib/factbase/term.rb +3 -20
- data/lib/factbase/term_once.rb +2 -19
- data/lib/factbase/terms/aggregates.rb +4 -21
- data/lib/factbase/terms/aliases.rb +2 -19
- data/lib/factbase/terms/casting.rb +2 -19
- data/lib/factbase/terms/debug.rb +2 -19
- data/lib/factbase/terms/defn.rb +2 -19
- data/lib/factbase/terms/logical.rb +3 -20
- data/lib/factbase/terms/math.rb +2 -19
- data/lib/factbase/terms/meta.rb +4 -21
- data/lib/factbase/terms/ordering.rb +3 -20
- data/lib/factbase/terms/strings.rb +2 -19
- data/lib/factbase/terms/system.rb +2 -19
- data/lib/factbase/to_json.rb +2 -19
- data/lib/factbase/to_xml.rb +2 -19
- data/lib/factbase/to_yaml.rb +2 -19
- data/lib/factbase.rb +48 -50
- data/test/factbase/terms/test_aggregates.rb +2 -19
- data/test/factbase/terms/test_aliases.rb +2 -19
- data/test/factbase/terms/test_casting.rb +2 -19
- data/test/factbase/terms/test_debug.rb +2 -19
- data/test/factbase/terms/test_defn.rb +2 -19
- data/test/factbase/terms/test_logical.rb +2 -19
- data/test/factbase/terms/test_math.rb +2 -19
- data/test/factbase/terms/test_meta.rb +2 -19
- data/test/factbase/terms/test_ordering.rb +2 -19
- data/test/factbase/terms/test_strings.rb +2 -19
- data/test/factbase/terms/test_system.rb +2 -19
- data/test/factbase/test_accum.rb +2 -19
- data/test/factbase/test_churn.rb +40 -0
- data/test/factbase/test_fact.rb +2 -19
- data/test/factbase/test_flatten.rb +2 -19
- data/test/factbase/test_inv.rb +2 -19
- data/test/factbase/test_looged.rb +6 -23
- data/test/factbase/test_pre.rb +2 -19
- data/test/factbase/test_query.rb +2 -19
- data/test/factbase/test_rules.rb +2 -19
- data/test/factbase/test_syntax.rb +2 -19
- data/test/factbase/test_tallied.rb +71 -0
- data/test/factbase/test_taped.rb +36 -0
- data/test/factbase/test_tee.rb +2 -19
- data/test/factbase/test_term.rb +2 -19
- data/test/factbase/test_to_json.rb +2 -19
- data/test/factbase/test_to_xml.rb +2 -19
- data/test/factbase/test_to_yaml.rb +2 -19
- data/test/test__helper.rb +3 -19
- data/test/test_factbase.rb +81 -50
- metadata +12 -3
- data/.yamllint.yml +0 -29
data/lib/factbase/looged.rb
CHANGED
@@ -1,24 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2024-2025 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.
|
3
|
+
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
4
|
+
# SPDX-License-Identifier: MIT
|
22
5
|
|
23
6
|
require 'decoor'
|
24
7
|
require 'others'
|
@@ -41,10 +24,6 @@ class Factbase::Looged
|
|
41
24
|
|
42
25
|
decoor(:fb)
|
43
26
|
|
44
|
-
def dup
|
45
|
-
Factbase::Looged.new(@fb.dup, @loog)
|
46
|
-
end
|
47
|
-
|
48
27
|
def insert
|
49
28
|
start = Time.now
|
50
29
|
f = @fb.insert
|
@@ -56,14 +35,14 @@ class Factbase::Looged
|
|
56
35
|
Query.new(@fb, query, @loog)
|
57
36
|
end
|
58
37
|
|
59
|
-
def txn
|
38
|
+
def txn
|
60
39
|
start = Time.now
|
61
40
|
id = nil
|
62
41
|
rollback = false
|
63
42
|
r =
|
64
|
-
@fb.txn
|
43
|
+
@fb.txn do |fbt|
|
65
44
|
id = fbt.object_id
|
66
|
-
yield fbt
|
45
|
+
yield Factbase::Looged.new(fbt, @loog)
|
67
46
|
rescue Factbase::Rollback => e
|
68
47
|
rollback = true
|
69
48
|
raise e
|
@@ -71,7 +50,7 @@ class Factbase::Looged
|
|
71
50
|
if rollback
|
72
51
|
@loog.debug("Txn ##{id} rolled back in #{start.ago}")
|
73
52
|
else
|
74
|
-
@loog.debug("Txn ##{id} #{r ? 'modified' : 'didn\'t touch'} the factbase in #{start.ago}")
|
53
|
+
@loog.debug("Txn ##{id} #{r.positive? ? 'modified' : 'didn\'t touch'} the factbase in #{start.ago}")
|
75
54
|
end
|
76
55
|
r
|
77
56
|
end
|
data/lib/factbase/pre.rb
CHANGED
@@ -1,24 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2024-2025 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.
|
3
|
+
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
4
|
+
# SPDX-License-Identifier: MIT
|
22
5
|
|
23
6
|
require 'loog'
|
24
7
|
require 'decoor'
|
@@ -48,17 +31,15 @@ class Factbase::Pre
|
|
48
31
|
@block = block
|
49
32
|
end
|
50
33
|
|
51
|
-
def dup
|
52
|
-
Factbase::Pre.new(@fb.dup, &@block)
|
53
|
-
end
|
54
|
-
|
55
34
|
def insert
|
56
35
|
f = @fb.insert
|
57
36
|
@block.call(f, self)
|
58
37
|
f
|
59
38
|
end
|
60
39
|
|
61
|
-
def txn
|
62
|
-
@fb.txn
|
40
|
+
def txn
|
41
|
+
@fb.txn do |fbt|
|
42
|
+
yield Factbase::Pre.new(fbt, &@block)
|
43
|
+
end
|
63
44
|
end
|
64
45
|
end
|
data/lib/factbase/query.rb
CHANGED
@@ -1,24 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2024-2025 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.
|
3
|
+
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
4
|
+
# SPDX-License-Identifier: MIT
|
22
5
|
|
23
6
|
require_relative '../factbase'
|
24
7
|
require_relative 'syntax'
|
@@ -71,7 +54,7 @@ class Factbase::Query
|
|
71
54
|
a = Factbase::Accum.new(f, extras, false)
|
72
55
|
r = term.evaluate(a, @maps)
|
73
56
|
unless r.is_a?(TrueClass) || r.is_a?(FalseClass)
|
74
|
-
raise "Unexpected evaluation result
|
57
|
+
raise "Unexpected evaluation result of type #{r.class}, must be Boolean at #{@query.inspect}"
|
75
58
|
end
|
76
59
|
next unless r
|
77
60
|
yield Factbase::Accum.new(f, extras, true)
|
@@ -88,7 +71,7 @@ class Factbase::Query
|
|
88
71
|
params = params.transform_keys(&:to_s) if params.is_a?(Hash)
|
89
72
|
r = term.evaluate(Factbase::Tee.new(nil, params), @maps)
|
90
73
|
unless %w[String Integer Float Time Array NilClass].include?(r.class.to_s)
|
91
|
-
raise "Incorrect type #{r.class} returned by #{@query}"
|
74
|
+
raise "Incorrect type #{r.class} returned by #{@query.inspect}"
|
92
75
|
end
|
93
76
|
r
|
94
77
|
end
|
data/lib/factbase/query_once.rb
CHANGED
@@ -1,24 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2024-2025 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.
|
3
|
+
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
4
|
+
# SPDX-License-Identifier: MIT
|
22
5
|
|
23
6
|
require_relative '../factbase'
|
24
7
|
|
data/lib/factbase/rules.rb
CHANGED
@@ -1,24 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2024-2025 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.
|
3
|
+
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
4
|
+
# SPDX-License-Identifier: MIT
|
22
5
|
|
23
6
|
require 'decoor'
|
24
7
|
require 'others'
|
@@ -53,10 +36,6 @@ class Factbase::Rules
|
|
53
36
|
@uid = uid
|
54
37
|
end
|
55
38
|
|
56
|
-
def dup
|
57
|
-
Factbase::Rules.new(@fb.dup, @rules, @check, uid: @uid)
|
58
|
-
end
|
59
|
-
|
60
39
|
def insert
|
61
40
|
Fact.new(@fb.insert, @check)
|
62
41
|
end
|
@@ -65,12 +44,12 @@ class Factbase::Rules
|
|
65
44
|
Query.new(@fb.query(query), @check)
|
66
45
|
end
|
67
46
|
|
68
|
-
def txn
|
47
|
+
def txn
|
69
48
|
before = @check
|
70
49
|
later = Later.new(@uid)
|
71
50
|
@check = later
|
72
|
-
@fb.txn
|
73
|
-
yield fbt
|
51
|
+
@fb.txn do |fbt|
|
52
|
+
yield Factbase::Rules.new(fbt, @rules, @check, uid: @uid)
|
74
53
|
@check = before
|
75
54
|
fbt.query('(always)').each do |f|
|
76
55
|
next unless later.include?(f)
|
data/lib/factbase/syntax.rb
CHANGED
@@ -1,24 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2024-2025 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.
|
3
|
+
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
4
|
+
# SPDX-License-Identifier: MIT
|
22
5
|
|
23
6
|
require 'backtrace'
|
24
7
|
require 'time'
|
@@ -0,0 +1,93 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
4
|
+
# SPDX-License-Identifier: MIT
|
5
|
+
|
6
|
+
require 'decoor'
|
7
|
+
require 'others'
|
8
|
+
require_relative '../factbase'
|
9
|
+
require_relative 'churn'
|
10
|
+
|
11
|
+
# A decorator of a Factbase, that count all operations and then returns
|
12
|
+
# an instance of Factbase::Churn.
|
13
|
+
#
|
14
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
15
|
+
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
16
|
+
# License:: MIT
|
17
|
+
class Factbase::Tallied
|
18
|
+
attr_reader :churn
|
19
|
+
|
20
|
+
def initialize(fb, churn = Factbase::Churn.new)
|
21
|
+
raise 'The "fb" is nil' if fb.nil?
|
22
|
+
@fb = fb
|
23
|
+
@churn = churn
|
24
|
+
end
|
25
|
+
|
26
|
+
decoor(:fb)
|
27
|
+
|
28
|
+
def insert
|
29
|
+
f = Fact.new(@fb.insert, @churn)
|
30
|
+
@churn.append(1, 0, 0)
|
31
|
+
f
|
32
|
+
end
|
33
|
+
|
34
|
+
def query(query)
|
35
|
+
Query.new(@fb.query(query), @churn)
|
36
|
+
end
|
37
|
+
|
38
|
+
def txn
|
39
|
+
@fb.txn do |fbt|
|
40
|
+
yield Factbase::Tallied.new(fbt, @churn)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# Fact decorator.
|
45
|
+
#
|
46
|
+
# This is an internal class, it is not supposed to be instantiated directly.
|
47
|
+
class Fact
|
48
|
+
def initialize(fact, churn)
|
49
|
+
@fact = fact
|
50
|
+
@churn = churn
|
51
|
+
end
|
52
|
+
|
53
|
+
def to_s
|
54
|
+
@fact.to_s
|
55
|
+
end
|
56
|
+
|
57
|
+
def all_properties
|
58
|
+
@fact.all_properties
|
59
|
+
end
|
60
|
+
|
61
|
+
others do |*args|
|
62
|
+
r = @fact.method_missing(*args)
|
63
|
+
@churn.append(0, 0, 1) if args[0].to_s.end_with?('=')
|
64
|
+
r
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# Query decorator.
|
69
|
+
#
|
70
|
+
# This is an internal class, it is not supposed to be instantiated directly.
|
71
|
+
class Query
|
72
|
+
def initialize(query, churn)
|
73
|
+
@query = query
|
74
|
+
@churn = churn
|
75
|
+
end
|
76
|
+
|
77
|
+
def one(params = {})
|
78
|
+
@query.one(params)
|
79
|
+
end
|
80
|
+
|
81
|
+
def each(params = {}, &)
|
82
|
+
@query.each(params) do |f|
|
83
|
+
yield Fact.new(f, @churn)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def delete!
|
88
|
+
c = @query.delete!
|
89
|
+
@churn.append(0, c, 0)
|
90
|
+
c
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
4
|
+
# SPDX-License-Identifier: MIT
|
5
|
+
|
6
|
+
require_relative '../factbase'
|
7
|
+
|
8
|
+
# A decorator of an Array with HashMaps, that records facts that have been touched,
|
9
|
+
# using their +object_id+.
|
10
|
+
#
|
11
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
12
|
+
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
13
|
+
# License:: MIT
|
14
|
+
class Factbase::Taped
|
15
|
+
attr_reader :inserted, :deleted, :added
|
16
|
+
|
17
|
+
def initialize(origin, lookup: {})
|
18
|
+
@origin = origin
|
19
|
+
@inserted = []
|
20
|
+
@deleted = []
|
21
|
+
@added = []
|
22
|
+
@lookup = lookup
|
23
|
+
end
|
24
|
+
|
25
|
+
def find_by_object_id(oid)
|
26
|
+
o = @lookup[oid]
|
27
|
+
o = @origin.find { |m| m.object_id == oid } if o.nil?
|
28
|
+
o
|
29
|
+
end
|
30
|
+
|
31
|
+
def size
|
32
|
+
@origin.size
|
33
|
+
end
|
34
|
+
|
35
|
+
def <<(map)
|
36
|
+
@origin << (map)
|
37
|
+
# rubocop:disable Lint/HashCompareByIdentity
|
38
|
+
@lookup[map.object_id] = map
|
39
|
+
# rubocop:enable Lint/HashCompareByIdentity
|
40
|
+
@inserted.append(map.object_id)
|
41
|
+
end
|
42
|
+
|
43
|
+
def each
|
44
|
+
@origin.each do |m|
|
45
|
+
# rubocop:disable Lint/HashCompareByIdentity
|
46
|
+
@lookup[m.object_id] = m
|
47
|
+
# rubocop:enable Lint/HashCompareByIdentity
|
48
|
+
yield TapedHash.new(m, @added)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def delete_if
|
53
|
+
@origin.delete_if do |m|
|
54
|
+
r = yield m
|
55
|
+
if r
|
56
|
+
@lookup.delete(m.object_id)
|
57
|
+
@deleted.append(m.object_id)
|
58
|
+
end
|
59
|
+
r
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# Decorator of Hash.
|
64
|
+
class TapedHash
|
65
|
+
def initialize(origin, added)
|
66
|
+
@origin = origin
|
67
|
+
@added = added
|
68
|
+
end
|
69
|
+
|
70
|
+
def [](key)
|
71
|
+
v = @origin[key]
|
72
|
+
v = TapedArray.new(v, @origin.object_id, @added) if v.respond_to?(:each)
|
73
|
+
v
|
74
|
+
end
|
75
|
+
|
76
|
+
def []=(key, value)
|
77
|
+
@origin[key] = value
|
78
|
+
@added.append(@origin.object_id)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# Decorator of Array.
|
83
|
+
class TapedArray
|
84
|
+
def initialize(origin, oid, added)
|
85
|
+
@origin = origin
|
86
|
+
@oid = oid
|
87
|
+
@added = added
|
88
|
+
end
|
89
|
+
|
90
|
+
def each(&)
|
91
|
+
@origin.each(&)
|
92
|
+
end
|
93
|
+
|
94
|
+
def to_a
|
95
|
+
@origin.to_a
|
96
|
+
end
|
97
|
+
|
98
|
+
def any?(&)
|
99
|
+
p 1
|
100
|
+
@origin.any?(&)
|
101
|
+
end
|
102
|
+
|
103
|
+
def <<(item)
|
104
|
+
@added.append(@oid)
|
105
|
+
@origin << (item)
|
106
|
+
end
|
107
|
+
|
108
|
+
def uniq!
|
109
|
+
@added.append(@oid)
|
110
|
+
@origin.uniq!
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
data/lib/factbase/tee.rb
CHANGED
@@ -1,24 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2024-2025 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.
|
3
|
+
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
4
|
+
# SPDX-License-Identifier: MIT
|
22
5
|
|
23
6
|
require 'others'
|
24
7
|
require_relative '../factbase'
|
data/lib/factbase/term.rb
CHANGED
@@ -1,24 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2024-2025 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.
|
3
|
+
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
4
|
+
# SPDX-License-Identifier: MIT
|
22
5
|
|
23
6
|
require 'backtrace'
|
24
7
|
require_relative '../factbase'
|
@@ -194,7 +177,7 @@ class Factbase::Term
|
|
194
177
|
v = v.evaluate(fact, maps) if v.is_a?(Factbase::Term)
|
195
178
|
v = fact[v.to_s] if v.is_a?(Symbol)
|
196
179
|
return v if v.nil?
|
197
|
-
v = [v] unless v.
|
180
|
+
v = [v] unless v.respond_to?(:each)
|
198
181
|
v
|
199
182
|
end
|
200
183
|
end
|
data/lib/factbase/term_once.rb
CHANGED
@@ -1,24 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2024-2025 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.
|
3
|
+
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
4
|
+
# SPDX-License-Identifier: MIT
|
22
5
|
|
23
6
|
require_relative '../factbase'
|
24
7
|
|
@@ -1,24 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2024-2025 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.
|
3
|
+
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
4
|
+
# SPDX-License-Identifier: MIT
|
22
5
|
|
23
6
|
require_relative '../../factbase'
|
24
7
|
|
@@ -67,7 +50,7 @@ module Factbase::Term::Aggregates
|
|
67
50
|
maps.each do |m|
|
68
51
|
vv = m[k.to_s]
|
69
52
|
next if vv.nil?
|
70
|
-
vv = [vv] unless vv.
|
53
|
+
vv = [vv] unless vv.respond_to?(:each)
|
71
54
|
vv.each do |v|
|
72
55
|
sum += v
|
73
56
|
end
|
@@ -99,7 +82,7 @@ module Factbase::Term::Aggregates
|
|
99
82
|
maps.each do |m|
|
100
83
|
vv = m[k.to_s]
|
101
84
|
next if vv.nil?
|
102
|
-
vv = [vv] unless vv.
|
85
|
+
vv = [vv] unless vv.respond_to?(:each)
|
103
86
|
vv.each do |v|
|
104
87
|
best = v if best.nil? || yield(v, best)
|
105
88
|
end
|
@@ -1,24 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2024-2025 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.
|
3
|
+
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
4
|
+
# SPDX-License-Identifier: MIT
|
22
5
|
|
23
6
|
require_relative '../../factbase'
|
24
7
|
|
@@ -1,24 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2024-2025 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.
|
3
|
+
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
4
|
+
# SPDX-License-Identifier: MIT
|
22
5
|
|
23
6
|
require_relative '../../factbase'
|
24
7
|
|