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.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/.0pdd.yml +2 -19
  3. data/.github/workflows/actionlint.yml +4 -20
  4. data/.github/workflows/benchmark.yml +10 -25
  5. data/.github/workflows/codecov.yml +6 -20
  6. data/.github/workflows/copyrights.yml +4 -19
  7. data/.github/workflows/markdown-lint.yml +4 -19
  8. data/.github/workflows/pdd.yml +4 -19
  9. data/.github/workflows/rake.yml +5 -21
  10. data/.github/workflows/reuse.yml +19 -0
  11. data/.github/workflows/xcop.yml +4 -19
  12. data/.github/workflows/yamllint.yml +4 -21
  13. data/.gitignore +1 -0
  14. data/.rubocop.yml +5 -21
  15. data/.rultor.yml +3 -19
  16. data/.simplecov +2 -19
  17. data/Gemfile +8 -24
  18. data/Gemfile.lock +40 -31
  19. data/LICENSES/MIT.txt +21 -0
  20. data/README.md +40 -10
  21. data/REUSE.toml +25 -0
  22. data/Rakefile +3 -28
  23. data/benchmarks/simple.rb +55 -24
  24. data/factbase.gemspec +2 -19
  25. data/lib/factbase/accum.rb +4 -21
  26. data/lib/factbase/churn.rb +44 -0
  27. data/lib/factbase/fact.rb +2 -19
  28. data/lib/factbase/flatten.rb +2 -19
  29. data/lib/factbase/inv.rb +6 -25
  30. data/lib/factbase/light.rb +32 -0
  31. data/lib/factbase/looged.rb +6 -27
  32. data/lib/factbase/pre.rb +6 -25
  33. data/lib/factbase/query.rb +4 -21
  34. data/lib/factbase/query_once.rb +2 -19
  35. data/lib/factbase/rules.rb +5 -26
  36. data/lib/factbase/syntax.rb +2 -19
  37. data/lib/factbase/tallied.rb +93 -0
  38. data/lib/factbase/taped.rb +113 -0
  39. data/lib/factbase/tee.rb +2 -19
  40. data/lib/factbase/term.rb +3 -20
  41. data/lib/factbase/term_once.rb +2 -19
  42. data/lib/factbase/terms/aggregates.rb +4 -21
  43. data/lib/factbase/terms/aliases.rb +2 -19
  44. data/lib/factbase/terms/casting.rb +2 -19
  45. data/lib/factbase/terms/debug.rb +2 -19
  46. data/lib/factbase/terms/defn.rb +2 -19
  47. data/lib/factbase/terms/logical.rb +3 -20
  48. data/lib/factbase/terms/math.rb +2 -19
  49. data/lib/factbase/terms/meta.rb +4 -21
  50. data/lib/factbase/terms/ordering.rb +3 -20
  51. data/lib/factbase/terms/strings.rb +2 -19
  52. data/lib/factbase/terms/system.rb +2 -19
  53. data/lib/factbase/to_json.rb +2 -19
  54. data/lib/factbase/to_xml.rb +2 -19
  55. data/lib/factbase/to_yaml.rb +2 -19
  56. data/lib/factbase.rb +48 -50
  57. data/test/factbase/terms/test_aggregates.rb +2 -19
  58. data/test/factbase/terms/test_aliases.rb +2 -19
  59. data/test/factbase/terms/test_casting.rb +2 -19
  60. data/test/factbase/terms/test_debug.rb +2 -19
  61. data/test/factbase/terms/test_defn.rb +2 -19
  62. data/test/factbase/terms/test_logical.rb +2 -19
  63. data/test/factbase/terms/test_math.rb +2 -19
  64. data/test/factbase/terms/test_meta.rb +2 -19
  65. data/test/factbase/terms/test_ordering.rb +2 -19
  66. data/test/factbase/terms/test_strings.rb +2 -19
  67. data/test/factbase/terms/test_system.rb +2 -19
  68. data/test/factbase/test_accum.rb +2 -19
  69. data/test/factbase/test_churn.rb +40 -0
  70. data/test/factbase/test_fact.rb +2 -19
  71. data/test/factbase/test_flatten.rb +2 -19
  72. data/test/factbase/test_inv.rb +2 -19
  73. data/test/factbase/test_looged.rb +6 -23
  74. data/test/factbase/test_pre.rb +2 -19
  75. data/test/factbase/test_query.rb +2 -19
  76. data/test/factbase/test_rules.rb +2 -19
  77. data/test/factbase/test_syntax.rb +2 -19
  78. data/test/factbase/test_tallied.rb +71 -0
  79. data/test/factbase/test_taped.rb +36 -0
  80. data/test/factbase/test_tee.rb +2 -19
  81. data/test/factbase/test_term.rb +2 -19
  82. data/test/factbase/test_to_json.rb +2 -19
  83. data/test/factbase/test_to_xml.rb +2 -19
  84. data/test/factbase/test_to_yaml.rb +2 -19
  85. data/test/test__helper.rb +3 -19
  86. data/test/test_factbase.rb +81 -50
  87. metadata +12 -3
  88. data/.yamllint.yml +0 -29
@@ -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(this = self, &)
38
+ def txn
60
39
  start = Time.now
61
40
  id = nil
62
41
  rollback = false
63
42
  r =
64
- @fb.txn(this) do |fbt|
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(this = self, &)
62
- @fb.txn(this, &)
40
+ def txn
41
+ @fb.txn do |fbt|
42
+ yield Factbase::Pre.new(fbt, &@block)
43
+ end
63
44
  end
64
45
  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
  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 (#{r.class}), must be Boolean at #{@query}"
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
@@ -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 '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(this = self, &)
47
+ def txn
69
48
  before = @check
70
49
  later = Later.new(@uid)
71
50
  @check = later
72
- @fb.txn(this) do |fbt|
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)
@@ -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.is_a?(Array)
180
+ v = [v] unless v.respond_to?(:each)
198
181
  v
199
182
  end
200
183
  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
 
@@ -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.is_a?(Array)
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.is_a?(Array)
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