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.
Files changed (87) 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 +21 -0
  11. data/.github/workflows/xcop.yml +4 -19
  12. data/.github/workflows/yamllint.yml +4 -21
  13. data/.rubocop.yml +4 -21
  14. data/.rultor.yml +3 -19
  15. data/.simplecov +2 -19
  16. data/Gemfile +8 -24
  17. data/Gemfile.lock +53 -43
  18. data/LICENSES/MIT.txt +21 -0
  19. data/README.md +24 -0
  20. data/REUSE.toml +17 -0
  21. data/Rakefile +3 -28
  22. data/benchmarks/simple.rb +2 -19
  23. data/factbase.gemspec +2 -19
  24. data/lib/factbase/accum.rb +2 -19
  25. data/lib/factbase/churn.rb +36 -0
  26. data/lib/factbase/fact.rb +2 -19
  27. data/lib/factbase/flatten.rb +2 -19
  28. data/lib/factbase/inv.rb +6 -25
  29. data/lib/factbase/light.rb +32 -0
  30. data/lib/factbase/looged.rb +5 -26
  31. data/lib/factbase/pre.rb +6 -25
  32. data/lib/factbase/query.rb +4 -21
  33. data/lib/factbase/query_once.rb +2 -19
  34. data/lib/factbase/rules.rb +5 -26
  35. data/lib/factbase/syntax.rb +13 -25
  36. data/lib/factbase/tallied.rb +93 -0
  37. data/lib/factbase/taped.rb +88 -0
  38. data/lib/factbase/tee.rb +2 -19
  39. data/lib/factbase/term.rb +2 -19
  40. data/lib/factbase/term_once.rb +2 -19
  41. data/lib/factbase/terms/aggregates.rb +2 -19
  42. data/lib/factbase/terms/aliases.rb +2 -19
  43. data/lib/factbase/terms/casting.rb +2 -19
  44. data/lib/factbase/terms/debug.rb +2 -19
  45. data/lib/factbase/terms/defn.rb +2 -19
  46. data/lib/factbase/terms/logical.rb +2 -19
  47. data/lib/factbase/terms/math.rb +2 -19
  48. data/lib/factbase/terms/meta.rb +2 -19
  49. data/lib/factbase/terms/ordering.rb +2 -19
  50. data/lib/factbase/terms/strings.rb +2 -19
  51. data/lib/factbase/terms/system.rb +2 -19
  52. data/lib/factbase/to_json.rb +2 -19
  53. data/lib/factbase/to_xml.rb +2 -19
  54. data/lib/factbase/to_yaml.rb +2 -19
  55. data/lib/factbase.rb +38 -48
  56. data/test/factbase/terms/test_aggregates.rb +2 -19
  57. data/test/factbase/terms/test_aliases.rb +2 -19
  58. data/test/factbase/terms/test_casting.rb +2 -19
  59. data/test/factbase/terms/test_debug.rb +2 -19
  60. data/test/factbase/terms/test_defn.rb +2 -19
  61. data/test/factbase/terms/test_logical.rb +2 -19
  62. data/test/factbase/terms/test_math.rb +2 -19
  63. data/test/factbase/terms/test_meta.rb +2 -19
  64. data/test/factbase/terms/test_ordering.rb +2 -19
  65. data/test/factbase/terms/test_strings.rb +2 -19
  66. data/test/factbase/terms/test_system.rb +2 -19
  67. data/test/factbase/test_accum.rb +2 -19
  68. data/test/factbase/test_churn.rb +31 -0
  69. data/test/factbase/test_fact.rb +2 -19
  70. data/test/factbase/test_flatten.rb +2 -19
  71. data/test/factbase/test_inv.rb +2 -19
  72. data/test/factbase/test_looged.rb +2 -19
  73. data/test/factbase/test_pre.rb +2 -19
  74. data/test/factbase/test_query.rb +2 -19
  75. data/test/factbase/test_rules.rb +2 -19
  76. data/test/factbase/test_syntax.rb +24 -19
  77. data/test/factbase/test_tallied.rb +71 -0
  78. data/test/factbase/test_taped.rb +37 -0
  79. data/test/factbase/test_tee.rb +2 -19
  80. data/test/factbase/test_term.rb +2 -19
  81. data/test/factbase/test_to_json.rb +2 -19
  82. data/test/factbase/test_to_xml.rb +2 -19
  83. data/test/factbase/test_to_yaml.rb +2 -19
  84. data/test/test__helper.rb +3 -19
  85. data/test/test_factbase.rb +67 -45
  86. metadata +12 -3
  87. data/.yamllint.yml +0 -29
data/Gemfile.lock CHANGED
@@ -14,24 +14,23 @@ PATH
14
14
  GEM
15
15
  remote: https://rubygems.org/
16
16
  specs:
17
- actionpack (7.2.2.1)
18
- actionview (= 7.2.2.1)
19
- activesupport (= 7.2.2.1)
17
+ actionpack (8.0.1)
18
+ actionview (= 8.0.1)
19
+ activesupport (= 8.0.1)
20
20
  nokogiri (>= 1.8.5)
21
- racc
22
- rack (>= 2.2.4, < 3.2)
21
+ rack (>= 2.2.4)
23
22
  rack-session (>= 1.0.1)
24
23
  rack-test (>= 0.6.3)
25
24
  rails-dom-testing (~> 2.2)
26
25
  rails-html-sanitizer (~> 1.6)
27
26
  useragent (~> 0.16)
28
- actionview (7.2.2.1)
29
- activesupport (= 7.2.2.1)
27
+ actionview (8.0.1)
28
+ activesupport (= 8.0.1)
30
29
  builder (~> 3.1)
31
30
  erubi (~> 1.11)
32
31
  rails-dom-testing (~> 2.2)
33
32
  rails-html-sanitizer (~> 1.6)
34
- activesupport (7.2.2.1)
33
+ activesupport (8.0.1)
35
34
  base64
36
35
  benchmark (>= 0.3)
37
36
  bigdecimal
@@ -43,6 +42,7 @@ GEM
43
42
  minitest (>= 5.1)
44
43
  securerandom (>= 0.3)
45
44
  tzinfo (~> 2.0, >= 2.0.5)
45
+ uri (>= 0.13.1)
46
46
  ansi (1.5.0)
47
47
  ast (2.4.2)
48
48
  backtrace (0.4.0)
@@ -55,7 +55,7 @@ GEM
55
55
  crass (1.0.6)
56
56
  date (3.4.1)
57
57
  decoor (0.0.1)
58
- diff-lcs (1.5.1)
58
+ diff-lcs (1.6.0)
59
59
  docile (1.4.1)
60
60
  drb (2.2.1)
61
61
  erubi (1.13.1)
@@ -66,9 +66,10 @@ GEM
66
66
  pp (>= 0.6.0)
67
67
  rdoc (>= 4.0.0)
68
68
  reline (>= 0.4.2)
69
- json (2.9.1)
69
+ json (2.10.1)
70
70
  language_server-protocol (3.17.0.4)
71
- logger (1.6.5)
71
+ lint_roller (1.1.0)
72
+ logger (1.6.6)
72
73
  loofah (2.24.0)
73
74
  crass (~> 1.0.2)
74
75
  nokogiri (>= 1.12.0)
@@ -79,17 +80,17 @@ GEM
79
80
  builder
80
81
  minitest (>= 5.0)
81
82
  ruby-progressbar
82
- nokogiri (1.18.2-arm64-darwin)
83
+ nokogiri (1.18.3-arm64-darwin)
83
84
  racc (~> 1.4)
84
- nokogiri (1.18.2-x64-mingw-ucrt)
85
+ nokogiri (1.18.3-x64-mingw-ucrt)
85
86
  racc (~> 1.4)
86
- nokogiri (1.18.2-x86_64-darwin)
87
+ nokogiri (1.18.3-x86_64-darwin)
87
88
  racc (~> 1.4)
88
- nokogiri (1.18.2-x86_64-linux-gnu)
89
+ nokogiri (1.18.3-x86_64-linux-gnu)
89
90
  racc (~> 1.4)
90
91
  others (0.0.3)
91
92
  parallel (1.26.3)
92
- parser (3.3.7.0)
93
+ parser (3.3.7.1)
93
94
  ast (~> 2.4.1)
94
95
  racc
95
96
  pp (0.6.2)
@@ -99,7 +100,7 @@ GEM
99
100
  date
100
101
  stringio
101
102
  racc (1.8.1)
102
- rack (3.1.8)
103
+ rack (3.1.10)
103
104
  rack-session (2.1.0)
104
105
  base64 (>= 0.1.0)
105
106
  rack (>= 3.0.0)
@@ -114,9 +115,9 @@ GEM
114
115
  rails-html-sanitizer (1.6.2)
115
116
  loofah (~> 2.21)
116
117
  nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
117
- railties (7.2.2.1)
118
- actionpack (= 7.2.2.1)
119
- activesupport (= 7.2.2.1)
118
+ railties (8.0.1)
119
+ actionpack (= 8.0.1)
120
+ activesupport (= 8.0.1)
120
121
  irb (~> 1.13)
121
122
  rackup (>= 1.0.0)
122
123
  rake (>= 12.2)
@@ -124,13 +125,13 @@ GEM
124
125
  zeitwerk (~> 2.6)
125
126
  rainbow (3.1.1)
126
127
  rake (13.2.1)
127
- rdoc (6.11.0)
128
+ rdoc (6.12.0)
128
129
  psych (>= 4.0.0)
129
130
  regexp_parser (2.10.0)
130
131
  reline (0.6.0)
131
132
  io-console (~> 0.5)
132
- rexml (3.4.0)
133
- rspec-core (3.13.2)
133
+ rexml (3.4.1)
134
+ rspec-core (3.13.3)
134
135
  rspec-support (~> 3.13.0)
135
136
  rspec-expectations (3.13.3)
136
137
  diff-lcs (>= 1.2.0, < 2.0)
@@ -138,7 +139,7 @@ GEM
138
139
  rspec-mocks (3.13.2)
139
140
  diff-lcs (>= 1.2.0, < 2.0)
140
141
  rspec-support (~> 3.13.0)
141
- rspec-rails (7.1.0)
142
+ rspec-rails (7.1.1)
142
143
  actionpack (>= 7.0)
143
144
  activesupport (>= 7.0)
144
145
  railties (>= 7.0)
@@ -147,26 +148,33 @@ GEM
147
148
  rspec-mocks (~> 3.13)
148
149
  rspec-support (~> 3.13)
149
150
  rspec-support (3.13.2)
150
- rubocop (1.71.0)
151
+ rubocop (1.72.2)
151
152
  json (~> 2.3)
152
- language_server-protocol (>= 3.17.0)
153
+ language_server-protocol (~> 3.17.0.2)
154
+ lint_roller (~> 1.1.0)
153
155
  parallel (~> 1.10)
154
156
  parser (>= 3.3.0.2)
155
157
  rainbow (>= 2.2.2, < 4.0)
156
158
  regexp_parser (>= 2.9.3, < 3.0)
157
- rubocop-ast (>= 1.36.2, < 2.0)
159
+ rubocop-ast (>= 1.38.0, < 2.0)
158
160
  ruby-progressbar (~> 1.7)
159
161
  unicode-display_width (>= 2.4.0, < 4.0)
160
- rubocop-ast (1.37.0)
162
+ rubocop-ast (1.38.0)
161
163
  parser (>= 3.3.1.0)
162
- rubocop-minitest (0.36.0)
163
- rubocop (>= 1.61, < 2.0)
164
- rubocop-ast (>= 1.31.1, < 2.0)
165
- rubocop-performance (1.23.1)
166
- rubocop (>= 1.48.1, < 2.0)
167
- rubocop-ast (>= 1.31.1, < 2.0)
168
- rubocop-rspec (3.4.0)
169
- rubocop (~> 1.61)
164
+ rubocop-minitest (0.37.1)
165
+ lint_roller (~> 1.1)
166
+ rubocop (>= 1.72.1, < 2.0)
167
+ rubocop-ast (>= 1.38.0, < 2.0)
168
+ rubocop-performance (1.24.0)
169
+ lint_roller (~> 1.1)
170
+ rubocop (>= 1.72.1, < 2.0)
171
+ rubocop-ast (>= 1.38.0, < 2.0)
172
+ rubocop-rake (0.7.1)
173
+ lint_roller (~> 1.1)
174
+ rubocop (>= 1.72.1)
175
+ rubocop-rspec (3.5.0)
176
+ lint_roller (~> 1.1)
177
+ rubocop (~> 1.72, >= 1.72.1)
170
178
  ruby-progressbar (1.13.0)
171
179
  securerandom (0.4.1)
172
180
  simplecov (0.22.0)
@@ -178,7 +186,7 @@ GEM
178
186
  simplecov (~> 0.19)
179
187
  simplecov-html (0.13.1)
180
188
  simplecov_json_formatter (0.1.4)
181
- stringio (3.1.2)
189
+ stringio (3.1.5)
182
190
  tago (0.0.2)
183
191
  thor (1.3.2)
184
192
  threads (0.4.1)
@@ -189,10 +197,11 @@ GEM
189
197
  unicode-display_width (3.1.4)
190
198
  unicode-emoji (~> 4.0, >= 4.0.4)
191
199
  unicode-emoji (4.0.4)
200
+ uri (1.0.2)
192
201
  useragent (0.16.11)
193
202
  yaml (0.4.0)
194
203
  yard (0.9.37)
195
- zeitwerk (2.6.18)
204
+ zeitwerk (2.7.2)
196
205
 
197
206
  PLATFORMS
198
207
  arm64-darwin-22
@@ -208,11 +217,12 @@ DEPENDENCIES
208
217
  minitest (= 5.25.4)
209
218
  minitest-reporters (= 1.7.1)
210
219
  rake (= 13.2.1)
211
- rspec-rails (= 7.1.0)
212
- rubocop (= 1.71.0)
213
- rubocop-minitest (= 0.36.0)
214
- rubocop-performance (= 1.23.1)
215
- rubocop-rspec (= 3.4.0)
220
+ rspec-rails (= 7.1.1)
221
+ rubocop (= 1.72.2)
222
+ rubocop-minitest (> 0)
223
+ rubocop-performance (> 0)
224
+ rubocop-rake (> 0)
225
+ rubocop-rspec (> 0)
216
226
  simplecov (= 0.22.0)
217
227
  simplecov-cobertura (= 2.1.0)
218
228
  threads (= 0.4.1)
data/LICENSES/MIT.txt ADDED
@@ -0,0 +1,21 @@
1
+ (The MIT License)
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 NONINFRINGEMENT. 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.
data/README.md CHANGED
@@ -64,6 +64,30 @@ if f[n].nil?
64
64
  end
65
65
  ```
66
66
 
67
+ You can make a factbase log all operations:
68
+
69
+ ```ruby
70
+ require 'loog'
71
+ require 'factbase/looged'
72
+ log = Loog::VERBOSE
73
+ fb = Factbase::Looged.new(Factbase.new, log)
74
+ f = fb.insert
75
+ ```
76
+
77
+ You can also count the amount of changes made to a factbase:
78
+
79
+ ```ruby
80
+ require 'loog'
81
+ require 'factbase/tailled'
82
+ log = Loog::VERBOSE
83
+ fb = Factbase::Tailled.new(Factbase.new, log)
84
+ f = fb.insert
85
+ churn = fb.churn
86
+ assert churn.inserted == 1
87
+ ```
88
+
89
+ ## Terms
90
+
67
91
  There are some boolean terms available in a query
68
92
  (they return either `true` or `false`):
69
93
 
data/REUSE.toml ADDED
@@ -0,0 +1,17 @@
1
+ # SPDX-FileCopyrightText: Copyright (c) 2025 Yegor Bugayenko
2
+ # SPDX-License-Identifier: MIT
3
+
4
+ version = 1
5
+ [[annotations]]
6
+ path = [
7
+ ".gitattributes",
8
+ ".gitignore",
9
+ ".gitleaksignore",
10
+ ".pdd",
11
+ "Gemfile.lock",
12
+ "README.md",
13
+ "renovate.json"
14
+ ]
15
+ precedence = "override"
16
+ SPDX-FileCopyrightText = "Copyright (c) 2025 Yegor Bugayenko"
17
+ SPDX-License-Identifier = "MIT"
data/Rakefile 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 NONINFRINGEMENT. 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 'rubygems'
24
7
  require 'rake'
@@ -32,7 +15,7 @@ def version
32
15
  Gem::Specification.load(Dir['*.gemspec'].first).version
33
16
  end
34
17
 
35
- task default: %i[clean test rubocop yard copyright]
18
+ task default: %i[clean test rubocop yard]
36
19
 
37
20
  require 'rake/testtask'
38
21
  desc 'Run all unit tests'
@@ -61,11 +44,3 @@ desc 'Run benchmark script'
61
44
  task :benchmark do
62
45
  ruby 'benchmarks/simple.rb'
63
46
  end
64
-
65
- task :copyright do
66
- sh "grep -q -r '#{Date.today.strftime('%Y')}' \
67
- --include '*.rb' \
68
- --include '*.txt' \
69
- --include 'Rakefile' \
70
- ."
71
- end
data/benchmarks/simple.rb CHANGED
@@ -1,25 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- # Copyright (c) 2024-2025 Yegor Bugayenko
5
- #
6
- # Permission is hereby granted, free of charge, to any person obtaining a copy
7
- # of this software and associated documentation files (the 'Software'), to deal
8
- # in the Software without restriction, including without limitation the rights
9
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- # copies of the Software, and to permit persons to whom the Software is
11
- # furnished to do so, subject to the following conditions:
12
- #
13
- # The above copyright notice and this permission notice shall be included in all
14
- # copies or substantial portions of the Software.
15
- #
16
- # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
19
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- # SOFTWARE.
4
+ # SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
5
+ # SPDX-License-Identifier: MIT
23
6
 
24
7
  require 'benchmark'
25
8
  require 'time'
data/factbase.gemspec 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 NONINFRINGEMENT. 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 'English'
24
7
  require_relative 'lib/factbase'
@@ -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'
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ # SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
4
+ # SPDX-License-Identifier: MIT
5
+
6
+ # A churn.
7
+ #
8
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
9
+ # Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
10
+ # License:: MIT
11
+ class Factbase::Churn
12
+ attr_reader :inserted, :deleted, :added
13
+
14
+ def initialize(ins = 0, del = 0, add = 0)
15
+ @mutex = Mutex.new
16
+ @inserted = ins
17
+ @deleted = del
18
+ @added = add
19
+ end
20
+
21
+ def to_s
22
+ "#{@inserted}i/#{@deleted}d/#{@added}a"
23
+ end
24
+
25
+ def zero?
26
+ @inserted.zero? && @deleted.zero? && @added.zero?
27
+ end
28
+
29
+ def append(ins, del, add)
30
+ @mutex.synchronize do
31
+ @inserted += ins
32
+ @deleted += del
33
+ @added += add
34
+ end
35
+ end
36
+ end
data/lib/factbase/fact.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 'json'
24
7
  require 'time'
@@ -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/inv.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 'decoor'
@@ -36,10 +19,6 @@ class Factbase::Inv
36
19
  @block = block
37
20
  end
38
21
 
39
- def dup
40
- Factbase::Inv.new(@fb.dup, &@block)
41
- end
42
-
43
22
  def insert
44
23
  Fact.new(@fb.insert, @block)
45
24
  end
@@ -48,8 +27,10 @@ class Factbase::Inv
48
27
  Query.new(@fb.query(query), @block)
49
28
  end
50
29
 
51
- def txn(this = self, &)
52
- @fb.txn(this, &)
30
+ def txn
31
+ @fb.txn do |fbt|
32
+ yield Factbase::Inv.new(fbt, &@block)
33
+ end
53
34
  end
54
35
 
55
36
  # Fact decorator.
@@ -0,0 +1,32 @@
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 a Factbase, that forbids most of the operations.
9
+ #
10
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
11
+ # Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
12
+ # License:: MIT
13
+ class Factbase::Light
14
+ attr_reader :cache
15
+
16
+ def initialize(fb, cache)
17
+ @fb = fb
18
+ @cache = cache
19
+ end
20
+
21
+ def size
22
+ @fb.size
23
+ end
24
+
25
+ def insert
26
+ @fb.insert
27
+ end
28
+
29
+ def query(query)
30
+ @fb.query(query)
31
+ end
32
+ 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 '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