factbase 0.0.21 → 0.0.22

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: dd8e28cf7e8e84fc0364bb8780775592aa86c415a05a49d4edd88bbc9a717a80
4
- data.tar.gz: ba7c821a3d229cb5f8b0e9fd1e632cd6d2e69c33eacb6b49751a5dd92902a23a
3
+ metadata.gz: 1f66d5d5358e584ad5c4f73d551ceb03d8627c7a8ebfeea75c4bfbdcd08479b9
4
+ data.tar.gz: 047d233242c56b0788b66d7eef912d4aed78706b7afe321b60fcf3daf32e0026
5
5
  SHA512:
6
- metadata.gz: 897308019e1fb3e05bad6e47ac06c39ec91250981e1b0206600a9a5620cb03b29c9dac866640994ac077e6bc3c418b5ea8aec7878e1e2b4587bab6d77b2cffb7
7
- data.tar.gz: 50172f65e3b8e40a30ec37155264c464b6a2849152ff9752270a38e8610c022506cd4b69cc1ed6869b2b8ecaa6056e3976d48a73642b067ffaedfc28ad887959
6
+ metadata.gz: b9749e3caf13ba363f5b76e598d007ccd731730579bc10851e29923f7304191eabf662ed0fd79864f02752f4ac5acd76537c7bbc352a97321e8aae13b1a94c0a
7
+ data.tar.gz: aa4a1cbe3bed556c478219fccdb3580925697cffa9dec838ed20f5f66b78006407a0ca3ff28e9dcc8adaa61f107b4566101401e99e3131bdbeb053f69505c910
data/factbase.gemspec CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |s|
26
26
  s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
27
27
  s.required_ruby_version = '>=2.3'
28
28
  s.name = 'factbase'
29
- s.version = '0.0.21'
29
+ s.version = '0.0.22'
30
30
  s.license = 'MIT'
31
31
  s.summary = 'Factbase'
32
32
  s.description = 'Fact base in memory and on disc'
@@ -42,7 +42,7 @@ class Factbase::Looged
42
42
 
43
43
  def insert
44
44
  f = @fb.insert
45
- @loog.debug("Inserted fact ##{f.id}")
45
+ @loog.debug('Inserted new fact')
46
46
  Fact.new(f, @loog)
47
47
  end
48
48
 
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) 2024 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.
22
+
23
+ require 'loog'
24
+
25
+ # A decorator of a Factbase, that runs a provided block on every +insert+.
26
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
27
+ # Copyright:: Copyright (c) 2024 Yegor Bugayenko
28
+ # License:: MIT
29
+ class Factbase::Pre
30
+ def initialize(fb, &block)
31
+ @fb = fb
32
+ @block = block
33
+ end
34
+
35
+ def empty?
36
+ @fb.empty?
37
+ end
38
+
39
+ def size
40
+ @fb.size
41
+ end
42
+
43
+ def insert
44
+ f = @fb.insert
45
+ @block.call(f)
46
+ f
47
+ end
48
+
49
+ def query(query)
50
+ @fb.query(query)
51
+ end
52
+
53
+ def export
54
+ @fb.export
55
+ end
56
+
57
+ def import(bytes)
58
+ @fb.import(bytes)
59
+ end
60
+
61
+ def to_json(opt = nil)
62
+ @fb.to_json(opt)
63
+ end
64
+
65
+ def to_xml
66
+ @fb.to_xml
67
+ end
68
+
69
+ def to_yaml
70
+ @fb.to_yaml
71
+ end
72
+ end
data/lib/factbase.rb CHANGED
@@ -53,8 +53,6 @@ class Factbase
53
53
  require_relative 'factbase/fact'
54
54
  map = {}
55
55
  @mutex.synchronize do
56
- f = Factbase::Fact.new(Mutex.new, map)
57
- f.id = @maps.size + 1
58
56
  @maps << map
59
57
  end
60
58
  Factbase::Fact.new(@mutex, map)
@@ -34,13 +34,13 @@ class TestLooged < Minitest::Test
34
34
  fb.insert
35
35
  fb.insert.bar = 3
36
36
  found = 0
37
- fb.query('(exists id)').each do |f|
38
- assert(42, f.id.positive?)
37
+ fb.query('(exists bar)').each do |f|
38
+ assert(42, f.bar.positive?)
39
39
  f.foo = 42
40
40
  assert_equal(42, f.foo)
41
41
  found += 1
42
42
  end
43
- assert_equal(2, found)
43
+ assert_equal(1, found)
44
44
  assert_equal(2, fb.size)
45
45
  end
46
46
 
@@ -72,8 +72,7 @@ class TestLooged < Minitest::Test
72
72
  fb.query('(exists bar)').each(&:to_s)
73
73
  fb.query('(not (exists bar))').delete!
74
74
  [
75
- 'Inserted fact #1',
76
- 'Inserted fact #2',
75
+ 'Inserted new fact',
77
76
  'Set \'bar\' to "3" (Integer)',
78
77
  'Found 1 fact(s) by \'(exists bar)\'',
79
78
  'Deleted 2 fact(s) by \'(not (exists bar))\''
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) 2024 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.
22
+
23
+ require 'minitest/autorun'
24
+ require 'loog'
25
+ require_relative '../../lib/factbase/pre'
26
+
27
+ # Test.
28
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
29
+ # Copyright:: Copyright (c) 2024 Yegor Bugayenko
30
+ # License:: MIT
31
+ class TestPre < Minitest::Test
32
+ def test_simple_setting
33
+ fb = Factbase::Pre.new(Factbase.new) { |f| f.foo = 42 }
34
+ f = fb.insert
35
+ assert_equal(42, f.foo)
36
+ end
37
+ end
@@ -34,15 +34,15 @@ class TestFactbase < Minitest::Test
34
34
  def test_simple_setting
35
35
  fb = Factbase.new
36
36
  fb.insert
37
- fb.insert
37
+ fb.insert.bar = 88
38
38
  found = 0
39
- fb.query('(exists id)').each do |f|
40
- assert(42, f.id.positive?)
39
+ fb.query('(exists bar)').each do |f|
40
+ assert(42, f.bar.positive?)
41
41
  f.foo = 42
42
42
  assert_equal(42, f.foo)
43
43
  found += 1
44
44
  end
45
- assert_equal(2, found)
45
+ assert_equal(1, found)
46
46
  assert_equal(2, fb.size)
47
47
  end
48
48
 
@@ -106,6 +106,5 @@ class TestFactbase < Minitest::Test
106
106
  assert_equal(2, yaml['facts'].size)
107
107
  assert_equal(42, yaml['facts'][0]['foo'][0])
108
108
  assert_equal(256, yaml['facts'][0]['foo'][1])
109
- assert_equal(2, yaml['facts'][1]['id'])
110
109
  end
111
110
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: factbase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.21
4
+ version: 0.0.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
@@ -97,6 +97,7 @@ files:
97
97
  - lib/factbase.rb
98
98
  - lib/factbase/fact.rb
99
99
  - lib/factbase/looged.rb
100
+ - lib/factbase/pre.rb
100
101
  - lib/factbase/query.rb
101
102
  - lib/factbase/spy.rb
102
103
  - lib/factbase/syntax.rb
@@ -105,6 +106,7 @@ files:
105
106
  - renovate.json
106
107
  - test/factbase/test_fact.rb
107
108
  - test/factbase/test_looged.rb
109
+ - test/factbase/test_pre.rb
108
110
  - test/factbase/test_query.rb
109
111
  - test/factbase/test_spy.rb
110
112
  - test/factbase/test_syntax.rb