factbase 0.0.16 → 0.0.17

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: a8038d22144d137a5f6681fc6d87305b6266613317109c8303477a0ef5deffa8
4
- data.tar.gz: d22085de542559b452f7a368418a821e83643658ff940fdfecbe698ffe16aa65
3
+ metadata.gz: d7ba6b0db6da2ae4a2075896ff5b8365716d881eab694e0c848063cfb0b19270
4
+ data.tar.gz: 53e1f409d20404d60827545927f1b88797708889d18fc0177d176a7ae93e9a68
5
5
  SHA512:
6
- metadata.gz: aa35c8dd802f4622842cc2c486cc26f3032dfc3ff525f6d97d8185ec6297b8fb5ad45a7dcf010bd7ce5b12b6aae2eb5721f1352f16666513818c2b30470ade17
7
- data.tar.gz: f4cfcaa303d1c74485760b56b93112003230f955f0b589921beb43d3a8ff83e7b9cfab07d6e4d42cd514b3d1100393611a40f37c287357b99408696e6caa7b6b
6
+ metadata.gz: 5f2db2983906007c6d4e12bb63b730e277d055c0f4768f41f6bc3ac68a6bccf6fa59226fa8ab417c41f0f53dfa163af59d7732e9082800494268e3d047de6f0c
7
+ data.tar.gz: 9c77ce233f61637e0bec39b72da43fdc5403d0e098b4f4505747bce634233810acaaa88e65aa59c6ded4f8aef870b25823f04f051999ec9e221a26b5520960f9
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.16'
29
+ s.version = '0.0.17'
30
30
  s.license = 'MIT'
31
31
  s.summary = 'Factbase'
32
32
  s.description = 'Fact base in memory and on disc'
@@ -38,6 +38,7 @@ Gem::Specification.new do |s|
38
38
  s.rdoc_options = ['--charset=UTF-8']
39
39
  s.extra_rdoc_files = ['README.md', 'LICENSE.txt']
40
40
  s.add_runtime_dependency 'json', '~> 2.7'
41
+ s.add_runtime_dependency 'loog', '~>0.2'
41
42
  s.add_runtime_dependency 'nokogiri', '~> 1.10'
42
43
  s.add_runtime_dependency 'yaml', '~> 0.3'
43
44
  s.metadata['rubygems_mfa_required'] = 'true'
@@ -0,0 +1,122 @@
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 logs all operations.
26
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
27
+ # Copyright:: Copyright (c) 2024 Yegor Bugayenko
28
+ # License:: MIT
29
+ class Factbase::Looged
30
+ def initialize(fb, loog)
31
+ @fb = fb
32
+ @loog = loog
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
+ @loog.debug("Inserted fact ##{f.id}")
46
+ Fact.new(f, @loog)
47
+ end
48
+
49
+ def query(query)
50
+ Query.new(@fb.query(query), query, @loog)
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
+
73
+ # Fact decorator.
74
+ class Fact
75
+ def initialize(fact, loog)
76
+ @fact = fact
77
+ @loog = loog
78
+ end
79
+
80
+ def to_s
81
+ @fact.to_s
82
+ end
83
+
84
+ def method_missing(*args)
85
+ r = @fact.method_missing(*args)
86
+ k = args[0].to_s
87
+ @loog.debug("Set '#{k[0..-2]}' to '#{args[1]}'") if k.end_with?('=')
88
+ r
89
+ end
90
+
91
+ # rubocop:disable Style/OptionalBooleanParameter
92
+ def respond_to?(method, include_private = false)
93
+ # rubocop:enable Style/OptionalBooleanParameter
94
+ @fact.respond_to?(method, include_private)
95
+ end
96
+
97
+ def respond_to_missing?(method, include_private = false)
98
+ @fact.respond_to_missing?(method, include_private)
99
+ end
100
+ end
101
+
102
+ # Query decorator.
103
+ class Query
104
+ def initialize(query, expr, loog)
105
+ @query = query
106
+ @expr = expr
107
+ @loog = loog
108
+ end
109
+
110
+ def each(&)
111
+ r = @query.each(&)
112
+ @loog.debug("Found #{r} facts by '#{@expr}'")
113
+ r
114
+ end
115
+
116
+ def delete!
117
+ r = @query.delete!
118
+ @loog.debug("Deleted #{r} facts by '#{@expr}'")
119
+ r
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,46 @@
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/looged'
26
+
27
+ # Test.
28
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
29
+ # Copyright:: Copyright (c) 2024 Yegor Bugayenko
30
+ # License:: MIT
31
+ class TestLooged < Minitest::Test
32
+ def test_simple_setting
33
+ fb = Factbase::Looged.new(Factbase.new, Loog::NULL)
34
+ fb.insert
35
+ fb.insert.bar = 3
36
+ found = 0
37
+ fb.query('(exists id)').each do |f|
38
+ assert(42, f.id.positive?)
39
+ f.foo = 42
40
+ assert_equal(42, f.foo)
41
+ found += 1
42
+ end
43
+ assert_equal(2, found)
44
+ assert_equal(2, fb.size)
45
+ end
46
+ end
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.16
4
+ version: 0.0.17
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-05-14 00:00:00.000000000 Z
11
+ date: 2024-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: loog
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.2'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: nokogiri
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -82,6 +96,7 @@ files:
82
96
  - factbase.gemspec
83
97
  - lib/factbase.rb
84
98
  - lib/factbase/fact.rb
99
+ - lib/factbase/looged.rb
85
100
  - lib/factbase/query.rb
86
101
  - lib/factbase/spy.rb
87
102
  - lib/factbase/syntax.rb
@@ -89,6 +104,7 @@ files:
89
104
  - lib/factbase/white_list.rb
90
105
  - renovate.json
91
106
  - test/factbase/test_fact.rb
107
+ - test/factbase/test_looged.rb
92
108
  - test/factbase/test_query.rb
93
109
  - test/factbase/test_spy.rb
94
110
  - test/factbase/test_syntax.rb