factbase 0.5.1 → 0.6.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 +21 -0
- data/.github/workflows/xcop.yml +4 -19
- data/.github/workflows/yamllint.yml +4 -21
- data/.rubocop.yml +4 -21
- data/.rultor.yml +3 -19
- data/.simplecov +2 -19
- data/Gemfile +8 -24
- data/Gemfile.lock +53 -43
- data/LICENSES/MIT.txt +21 -0
- data/README.md +24 -0
- data/REUSE.toml +17 -0
- data/Rakefile +3 -28
- data/benchmarks/simple.rb +2 -19
- data/factbase.gemspec +2 -19
- data/lib/factbase/accum.rb +2 -19
- data/lib/factbase/churn.rb +36 -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 +5 -26
- 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 +13 -25
- data/lib/factbase/tallied.rb +93 -0
- data/lib/factbase/taped.rb +88 -0
- data/lib/factbase/tee.rb +2 -19
- data/lib/factbase/term.rb +2 -19
- data/lib/factbase/term_once.rb +2 -19
- data/lib/factbase/terms/aggregates.rb +2 -19
- 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 +2 -19
- data/lib/factbase/terms/math.rb +2 -19
- data/lib/factbase/terms/meta.rb +2 -19
- data/lib/factbase/terms/ordering.rb +2 -19
- 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 +38 -48
- 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 +31 -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 +2 -19
- 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 +24 -19
- data/test/factbase/test_tallied.rb +71 -0
- data/test/factbase/test_taped.rb +37 -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 +67 -45
- metadata +12 -3
- data/.yamllint.yml +0 -29
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,25 +1,9 @@
|
|
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
|
|
6
|
+
require 'backtrace'
|
23
7
|
require 'time'
|
24
8
|
require_relative '../factbase'
|
25
9
|
require_relative 'fact'
|
@@ -56,6 +40,8 @@ class Factbase::Syntax
|
|
56
40
|
def initialize(fb, query, term: Factbase::Term)
|
57
41
|
@fb = fb
|
58
42
|
@query = query
|
43
|
+
raise "Term must be a Class, while #{term.class.name} provided" unless term.is_a?(Class)
|
44
|
+
raise "The 'term' must be a child of Factbase::Term, while #{term.name} provided" unless term <= Factbase::Term
|
59
45
|
@term = term
|
60
46
|
end
|
61
47
|
|
@@ -69,7 +55,7 @@ class Factbase::Syntax
|
|
69
55
|
t
|
70
56
|
end
|
71
57
|
rescue StandardError => e
|
72
|
-
err = "#{e.message} (#{
|
58
|
+
err = "#{e.message} (#{Backtrace.new(e)}) in \"#{@query}\""
|
73
59
|
err = "#{err}, tokens: #{@tokens}" unless @tokens.nil?
|
74
60
|
raise err
|
75
61
|
end
|
@@ -83,10 +69,10 @@ class Factbase::Syntax
|
|
83
69
|
raise 'No tokens' if @tokens.empty?
|
84
70
|
@ast ||= to_ast(@tokens, 0)
|
85
71
|
raise "Too many terms (#{@ast[1]} != #{@tokens.size})" if @ast[1] != @tokens.size
|
86
|
-
|
87
|
-
raise 'No terms found' if
|
88
|
-
raise "
|
89
|
-
|
72
|
+
t = @ast[0]
|
73
|
+
raise 'No terms found in the AST' if t.nil?
|
74
|
+
raise "#{t.class.name} is not an instance of #{@term}, thus not a proper term" unless t.is_a?(@term)
|
75
|
+
t
|
90
76
|
end
|
91
77
|
|
92
78
|
# Reads the stream of tokens, starting at the +at+ position. If the
|
@@ -114,7 +100,9 @@ class Factbase::Syntax
|
|
114
100
|
operands << operand
|
115
101
|
break if tokens[at] == :close
|
116
102
|
end
|
117
|
-
|
103
|
+
t = @term.new(@fb, op, operands)
|
104
|
+
t = Factbase::TermOnce.new(t, @fb.cache) if t.instance_of?(Factbase::Term)
|
105
|
+
[t, at + 1]
|
118
106
|
end
|
119
107
|
|
120
108
|
# Turns a query into an array of tokens.
|
@@ -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,88 @@
|
|
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)
|
18
|
+
@origin = origin
|
19
|
+
@inserted = []
|
20
|
+
@deleted = []
|
21
|
+
@added = []
|
22
|
+
end
|
23
|
+
|
24
|
+
def modified?
|
25
|
+
!@inserted.empty? || !@deleted.empty? || !@added.empty?
|
26
|
+
end
|
27
|
+
|
28
|
+
def size
|
29
|
+
@origin.size
|
30
|
+
end
|
31
|
+
|
32
|
+
def <<(map)
|
33
|
+
@origin << (map)
|
34
|
+
@inserted.append(map.object_id)
|
35
|
+
end
|
36
|
+
|
37
|
+
def each
|
38
|
+
@origin.each do |m|
|
39
|
+
yield TapedHash.new(m, @added)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def delete_if
|
44
|
+
@origin.delete_if do |m|
|
45
|
+
r = yield m
|
46
|
+
@deleted.append(m.object_id) if r
|
47
|
+
r
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# Decorator of Hash.
|
52
|
+
class TapedHash
|
53
|
+
def initialize(origin, added)
|
54
|
+
@origin = origin
|
55
|
+
@added = added
|
56
|
+
end
|
57
|
+
|
58
|
+
def [](key)
|
59
|
+
v = @origin[key]
|
60
|
+
v = TapedArray.new(v, @origin.object_id, @added) if v.is_a?(Array)
|
61
|
+
v
|
62
|
+
end
|
63
|
+
|
64
|
+
def []=(key, value)
|
65
|
+
@origin[key] = value
|
66
|
+
@added.append(@origin.object_id)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# Decorator of Array.
|
71
|
+
class TapedArray
|
72
|
+
def initialize(origin, oid, added)
|
73
|
+
@origin = origin
|
74
|
+
@oid = oid
|
75
|
+
@added = added
|
76
|
+
end
|
77
|
+
|
78
|
+
def <<(item)
|
79
|
+
@added.append(@oid)
|
80
|
+
@origin << (item)
|
81
|
+
end
|
82
|
+
|
83
|
+
def uniq!
|
84
|
+
@added.append(@oid)
|
85
|
+
@origin.uniq!
|
86
|
+
end
|
87
|
+
end
|
88
|
+
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'
|
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
|
|
@@ -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
|
|
data/lib/factbase/terms/debug.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/terms/defn.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
|
|