factbase 0.0.44 → 0.0.46

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7942029d876a9fee77f167bb9e9d7311445e16fa38c9654dfd6eae231fb9c366
4
- data.tar.gz: 102f08927aafc6900d4563e90cbabb9311166307e1ca57a9bd4e484ff8be684a
3
+ metadata.gz: b1a1f43a45551ecd6d7dc96d1fc2d64e72b535ad92869f28b6efd1c2aafa6619
4
+ data.tar.gz: 716e6a3a3e44f7f91249feec8e385463eba0a1cc9ec695f361367d2ed6e0a5eb
5
5
  SHA512:
6
- metadata.gz: d6877f4b3dbe627819256cda88214fd170e89e37521c2936daa0fed5a02b1450fc98157c53e92d2f38e48522dd617d901609ec1b23b96875abb68a7c231d5a47
7
- data.tar.gz: 482f13ec05d51bf726049ed44627ec2719ee17b1a5b387eb7ebb6ee98a760523702f9f81540e6e10ff2dc211a90321742c5796cb63ef9ee4aa64fa6777886b81
6
+ metadata.gz: 92de5dea89b80df3856a438d0d045ea7de3c5a607295cc7d11615bc1e4d730e4e8de4fbdd710da8d3d33046917d35ef44f6c2ef768ce8f7a2210b2e8524de224
7
+ data.tar.gz: 2ef47978b1ebbe1736cf6b7b4a8d231823cb8c958bf602a015a7b4ea703448b70ec1fcfcb2e1a212b162e1f0967c088eb302f5452c135b7021caae08333212ac
@@ -18,40 +18,13 @@
18
18
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
19
  # SOFTWARE.
20
20
  ---
21
- name: license
21
+ name: copyrights
22
22
  'on':
23
23
  push:
24
- branches:
25
- - master
26
24
  pull_request:
27
- branches:
28
- - master
29
25
  jobs:
30
- license:
26
+ copyrights:
31
27
  runs-on: ubuntu-22.04
32
28
  steps:
33
29
  - uses: actions/checkout@v4
34
- - shell: bash
35
- run: |
36
- header="Copyright (c) $(date +%Y) Yegor Bugayenko"
37
- failed="false"
38
- while IFS= read -r file; do
39
- if ! grep -q "${header}" "${file}"; then
40
- failed="true"
41
- echo "⚠️ Copyright header is not found in: ${file}"
42
- else
43
- echo "File looks good: ${file}"
44
- fi
45
- done < <(find . -type f \( \
46
- -name "Dockerfile" -o \
47
- -name "LICENSE.txt" -o \
48
- -name "Makefile" -o \
49
- -name "Rakefile" -o \
50
- -name "*.sh" -o \
51
- -name "*.rb" -o \
52
- -name "*.fe" -o \
53
- -name "*.yml" \
54
- \) -print)
55
- if [ "${failed}" = "true" ]; then
56
- exit 1
57
- fi
30
+ - uses: yegor256/copyrights-action@0.0.4
data/Gemfile CHANGED
@@ -28,7 +28,7 @@ gem 'rake', '13.2.1', require: false
28
28
  gem 'rspec-rails', '6.1.2', require: false
29
29
  gem 'rubocop', '1.64.1', require: false
30
30
  gem 'rubocop-performance', '1.21.0', require: false
31
- gem 'rubocop-rspec', '2.30.0', require: false
31
+ gem 'rubocop-rspec', '2.31.0', require: false
32
32
  gem 'simplecov', '0.22.0', require: false
33
33
  gem 'simplecov-cobertura', '2.1.0', require: false
34
34
  gem 'yard', '0.9.36', require: false
data/Gemfile.lock CHANGED
@@ -145,7 +145,7 @@ GEM
145
145
  rubocop-performance (1.21.0)
146
146
  rubocop (>= 1.48.1, < 2.0)
147
147
  rubocop-ast (>= 1.31.1, < 2.0)
148
- rubocop-rspec (2.30.0)
148
+ rubocop-rspec (2.31.0)
149
149
  rubocop (~> 1.40)
150
150
  rubocop-capybara (~> 2.17)
151
151
  rubocop-factory_bot (~> 2.22)
@@ -186,7 +186,7 @@ DEPENDENCIES
186
186
  rspec-rails (= 6.1.2)
187
187
  rubocop (= 1.64.1)
188
188
  rubocop-performance (= 1.21.0)
189
- rubocop-rspec (= 2.30.0)
189
+ rubocop-rspec (= 2.31.0)
190
190
  simplecov (= 0.22.0)
191
191
  simplecov-cobertura (= 2.1.0)
192
192
  yard (= 0.9.36)
@@ -22,6 +22,7 @@
22
22
 
23
23
  require 'time'
24
24
  require 'loog'
25
+ require_relative 'syntax'
25
26
 
26
27
  # A decorator of a Factbase, that logs all operations.
27
28
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
@@ -48,11 +49,19 @@ class Factbase::Looged
48
49
  end
49
50
 
50
51
  def query(query)
51
- Query.new(@fb.query(query), query, @loog)
52
+ Query.new(@fb, query, @loog)
52
53
  end
53
54
 
54
55
  def txn(this = self, &)
55
- @fb.txn(this, &)
56
+ before = @fb.size
57
+ tail = nil
58
+ r = @fb.txn(this) do |x|
59
+ tail = Factbase::Looged.elapsed do
60
+ yield x
61
+ end
62
+ end
63
+ @loog.debug("Txn #{r ? 'modified' : 'didn\'t touch'} #{before} facts #{tail}")
64
+ r
56
65
  end
57
66
 
58
67
  def export
@@ -106,8 +115,8 @@ class Factbase::Looged
106
115
  # This is an internal class, it is not supposed to be instantiated directly.
107
116
  #
108
117
  class Query
109
- def initialize(query, expr, loog)
110
- @query = query
118
+ def initialize(fb, expr, loog)
119
+ @fb = fb
111
120
  @expr = expr
112
121
  @loog = loog
113
122
  end
@@ -117,7 +126,7 @@ class Factbase::Looged
117
126
  if block_given?
118
127
  r = nil
119
128
  tail = Factbase::Looged.elapsed do
120
- r = @query.each(&)
129
+ r = @fb.query(@expr).each(&)
121
130
  end
122
131
  raise ".each of #{@query.class} returned #{r.class}" unless r.is_a?(Integer)
123
132
  if r.zero?
@@ -129,7 +138,7 @@ class Factbase::Looged
129
138
  else
130
139
  array = []
131
140
  tail = Factbase::Looged.elapsed do
132
- @query.each do |f|
141
+ @fb.query(@expr).each do |f|
133
142
  array << f
134
143
  end
135
144
  end
@@ -144,14 +153,17 @@ class Factbase::Looged
144
153
 
145
154
  def delete!
146
155
  r = nil
156
+ before = @fb.size
147
157
  tail = Factbase::Looged.elapsed do
148
- r = @query.delete!
158
+ r = @fb.query(@expr).delete!
149
159
  end
150
160
  raise ".delete! of #{@query.class} returned #{r.class}" unless r.is_a?(Integer)
151
- if r.zero?
152
- @loog.debug("Nothing deleted by '#{@expr}' #{tail}")
161
+ if before.zero?
162
+ @loog.debug("There were no facts, nothing deleted by '#{@expr}' #{tail}")
163
+ elsif r.zero?
164
+ @loog.debug("No facts out of #{before} deleted by '#{@expr}' #{tail}")
153
165
  else
154
- @loog.debug("Deleted #{r} fact(s) by '#{@expr}' #{tail}")
166
+ @loog.debug("Deleted #{r} fact(s) out of #{before} by '#{@expr}' #{tail}")
155
167
  end
156
168
  r
157
169
  end
data/lib/factbase.rb CHANGED
@@ -79,7 +79,7 @@ require 'yaml'
79
79
  # License:: MIT
80
80
  class Factbase
81
81
  # Current version of the gem (changed by .rultor.yml on every release)
82
- VERSION = '0.0.44'
82
+ VERSION = '0.0.46'
83
83
 
84
84
  # An exception that may be thrown in a transaction, to roll it back.
85
85
  class Rollback < StandardError; end
@@ -22,6 +22,7 @@
22
22
 
23
23
  require 'minitest/autorun'
24
24
  require 'loog'
25
+ require_relative '../../lib/factbase'
25
26
  require_relative '../../lib/factbase/looged'
26
27
 
27
28
  # Test.
@@ -44,6 +45,25 @@ class TestLooged < Minitest::Test
44
45
  assert_equal(2, fb.size)
45
46
  end
46
47
 
48
+ def test_with_txn
49
+ log = Loog::Buffer.new
50
+ fb = Factbase::Looged.new(Factbase.new, log)
51
+ assert(
52
+ fb.txn do |fbt|
53
+ fbt.insert.foo = 42
54
+ end
55
+ )
56
+ assert_equal(1, fb.size)
57
+ assert(log.to_s.include?('modified'), log)
58
+ end
59
+
60
+ def test_with_empty_txn
61
+ log = Loog::Buffer.new
62
+ fb = Factbase::Looged.new(Factbase.new, log)
63
+ assert(!fb.txn { |fbt| fbt.query('(always)').each.to_a })
64
+ assert(log.to_s.include?('didn\'t touch'), log)
65
+ end
66
+
47
67
  def test_returns_int
48
68
  fb = Factbase.new
49
69
  fb.insert
@@ -92,7 +112,7 @@ class TestLooged < Minitest::Test
92
112
  'Set \'bar\' to 3 (Integer)',
93
113
  'Set \'str\' to "Он поскорей звонит. Вбегает\n ... Отъехать в поле к двум дубкам." (String)',
94
114
  'Found 1 fact(s) by \'(exists bar)\'',
95
- 'Deleted 3 fact(s) by \'(not (exists bar))\''
115
+ 'Deleted 3 fact(s) out of 4 by \'(not (exists bar))\''
96
116
  ].each do |s|
97
117
  assert(log.to_s.include?(s), "#{log}\n")
98
118
  end
@@ -72,6 +72,14 @@ class TestFactbase < Minitest::Test
72
72
  assert_equal(2, fb2.size)
73
73
  end
74
74
 
75
+ def test_txn_returns_boolean
76
+ fb = Factbase.new
77
+ assert(fb.txn { true }.is_a?(FalseClass))
78
+ assert(fb.txn(&:insert).is_a?(TrueClass))
79
+ assert(fb.txn { |fbt| fbt.insert.bar = 42 })
80
+ assert(!fb.txn { |fbt| fbt.query('(always)').each.to_a })
81
+ end
82
+
75
83
  def test_run_txn
76
84
  fb = Factbase.new
77
85
  fb.txn do |fbt|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: factbase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.44
4
+ version: 0.0.46
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-06 00:00:00.000000000 Z
11
+ date: 2024-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -82,7 +82,7 @@ files:
82
82
  - ".gitattributes"
83
83
  - ".github/workflows/actionlint.yml"
84
84
  - ".github/workflows/codecov.yml"
85
- - ".github/workflows/license.yml"
85
+ - ".github/workflows/copyrights.yml"
86
86
  - ".github/workflows/markdown-lint.yml"
87
87
  - ".github/workflows/pdd.yml"
88
88
  - ".github/workflows/rake.yml"