factbase 0.0.52 → 0.0.53

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: a70fcc45481bd1611d6bf2ed5c41ef40fe6f1ce67494abfa769c3b859b215960
4
- data.tar.gz: 609bd76eaca6f4668bbbf5678514503edb1f9184e9abd62321dc02cdd614f80c
3
+ metadata.gz: c1a97c8ab8b636aead2a98c980db09739120d98be8be0bc57f666a3c74ab5ef2
4
+ data.tar.gz: 595422041561719af19046aceef46e7a15c5ec2e6702edb0e1b8e4e22ddece0f
5
5
  SHA512:
6
- metadata.gz: 97e8cc3c9f53349aaf85aa3f95ba9f0e2525dd85f242ade079083b4ffab042dbb0b3f1ad776573646f7fae0107e709404b70e340fc9660b99ef8770a313aa8a9
7
- data.tar.gz: e4d9404781d0314d4e6aa22f93affc3260fc053121c9e70204f8690d30de34feb26533254f15519b9e2562a5562e93398779d890ab78c3acc3afcd8ed8fba782
6
+ metadata.gz: 30a0906b9c5846728ae7430502c4267d167637220b2c96e7c36ea3a0455044438d478fb2f59db84fa17d9ccae0bad73dff1025d3b70d8f54316faf59dc11e323
7
+ data.tar.gz: 9807c7818a2ead9bfc3dda9fc83435ea13c37da0cc802acf1798de5e0473660e3d747f50a4da0cd584fe5758e9827b64a20fb3991efaeefad21e83bf92c0dece
data/Gemfile.lock CHANGED
@@ -3,9 +3,11 @@ PATH
3
3
  specs:
4
4
  factbase (0.0.0)
5
5
  backtrace (~> 0.3)
6
+ decoor (~> 0.0)
6
7
  json (~> 2.7)
7
8
  loog (~> 0.2)
8
9
  nokogiri (~> 1.10)
10
+ others (~> 0.0)
9
11
  tago (~> 0.0)
10
12
  yaml (~> 0.3)
11
13
 
@@ -46,6 +48,7 @@ GEM
46
48
  concurrent-ruby (1.3.3)
47
49
  connection_pool (2.4.1)
48
50
  crass (1.0.6)
51
+ decoor (0.0.1)
49
52
  diff-lcs (1.5.1)
50
53
  docile (1.4.0)
51
54
  drb (2.2.1)
@@ -72,6 +75,7 @@ GEM
72
75
  racc (~> 1.4)
73
76
  nokogiri (1.16.6-x86_64-linux)
74
77
  racc (~> 1.4)
78
+ others (0.0.3)
75
79
  parallel (1.25.1)
76
80
  parser (3.3.3.0)
77
81
  ast (~> 2.4.1)
@@ -79,7 +83,7 @@ GEM
79
83
  psych (5.1.2)
80
84
  stringio
81
85
  racc (1.8.0)
82
- rack (3.1.3)
86
+ rack (3.1.4)
83
87
  rack-session (2.0.0)
84
88
  rack (>= 3.0.0)
85
89
  rack-test (2.1.0)
data/factbase.gemspec CHANGED
@@ -43,9 +43,11 @@ Gem::Specification.new do |s|
43
43
  s.rdoc_options = ['--charset=UTF-8']
44
44
  s.extra_rdoc_files = ['README.md', 'LICENSE.txt']
45
45
  s.add_runtime_dependency 'backtrace', '~>0.3'
46
+ s.add_runtime_dependency 'decoor', '~>0.0'
46
47
  s.add_runtime_dependency 'json', '~>2.7'
47
48
  s.add_runtime_dependency 'loog', '~>0.2'
48
49
  s.add_runtime_dependency 'nokogiri', '~>1.10'
50
+ s.add_runtime_dependency 'others', '~>0.0'
49
51
  s.add_runtime_dependency 'tago', '~>0.0'
50
52
  s.add_runtime_dependency 'yaml', '~>0.3'
51
53
  s.metadata['rubygems_mfa_required'] = 'true'
@@ -20,6 +20,7 @@
20
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  # SOFTWARE.
22
22
 
23
+ require 'others'
23
24
  require_relative '../factbase'
24
25
 
25
26
  # Accumulator of props.
@@ -42,35 +43,25 @@ class Factbase::Accum
42
43
  "#{@fact} + #{@props}"
43
44
  end
44
45
 
45
- def method_missing(*args)
46
+ others do |*args|
46
47
  k = args[0].to_s
47
48
  if k.end_with?('=')
48
49
  kk = k[0..-2]
49
50
  @props[kk] = [] if @props[kk].nil?
50
51
  @props[kk] << args[1]
51
52
  @fact.method_missing(*args) if @pass
52
- return
53
- end
54
- if k == '[]'
53
+ elsif k == '[]'
55
54
  kk = args[1].to_s
56
55
  vv = @props[kk].nil? ? [] : @props[kk]
57
56
  vvv = @fact.method_missing(*args)
58
57
  vvv = [vvv] unless vvv.nil? || vvv.is_a?(Array)
59
58
  vv += vvv unless vvv.nil?
60
59
  vv.uniq!
61
- return vv.empty? ? nil : vv
60
+ vv.empty? ? nil : vv
61
+ elsif @props[k].nil?
62
+ @fact.method_missing(*args)
63
+ else
64
+ @props[k][0]
62
65
  end
63
- return @props[k][0] unless @props[k].nil?
64
- @fact.method_missing(*args)
65
- end
66
-
67
- # rubocop:disable Style/OptionalBooleanParameter
68
- def respond_to?(_method, _include_private = false)
69
- # rubocop:enable Style/OptionalBooleanParameter
70
- true
71
- end
72
-
73
- def respond_to_missing?(_method, _include_private = false)
74
- true
75
66
  end
76
67
  end
data/lib/factbase/fact.rb CHANGED
@@ -22,6 +22,7 @@
22
22
 
23
23
  require 'json'
24
24
  require 'time'
25
+ require 'others'
25
26
  require_relative '../factbase'
26
27
 
27
28
  # A single fact in a factbase.
@@ -57,7 +58,7 @@ class Factbase::Fact
57
58
  end
58
59
 
59
60
  # When a method is missing, this method is called.
60
- def method_missing(*args)
61
+ others do |*args|
61
62
  k = args[0].to_s
62
63
  if k.end_with?('=')
63
64
  kk = k[0..-2]
@@ -85,14 +86,4 @@ class Factbase::Fact
85
86
  v[0]
86
87
  end
87
88
  end
88
-
89
- # rubocop:disable Style/OptionalBooleanParameter
90
- def respond_to?(_method, _include_private = false)
91
- # rubocop:enable Style/OptionalBooleanParameter
92
- true
93
- end
94
-
95
- def respond_to_missing?(_method, _include_private = false)
96
- true
97
- end
98
89
  end
data/lib/factbase/inv.rb CHANGED
@@ -20,6 +20,8 @@
20
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  # SOFTWARE.
22
22
 
23
+ require 'others'
24
+ require 'decoor'
23
25
  require_relative '../factbase'
24
26
 
25
27
  # A decorator of a Factbase, that checks invariants on every set.
@@ -27,6 +29,8 @@ require_relative '../factbase'
27
29
  # Copyright:: Copyright (c) 2024 Yegor Bugayenko
28
30
  # License:: MIT
29
31
  class Factbase::Inv
32
+ decoor(:fb)
33
+
30
34
  def initialize(fb, &block)
31
35
  @fb = fb
32
36
  @block = block
@@ -36,10 +40,6 @@ class Factbase::Inv
36
40
  Factbase::Inv.new(@fb.dup, &@block)
37
41
  end
38
42
 
39
- def size
40
- @fb.size
41
- end
42
-
43
43
  def insert
44
44
  Fact.new(@fb.insert, @block)
45
45
  end
@@ -52,14 +52,6 @@ class Factbase::Inv
52
52
  @fb.txn(this, &)
53
53
  end
54
54
 
55
- def export
56
- @fb.export
57
- end
58
-
59
- def import(bytes)
60
- @fb.import(bytes)
61
- end
62
-
63
55
  # Fact decorator.
64
56
  #
65
57
  # This is an internal class, it is not supposed to be instantiated directly.
@@ -74,21 +66,11 @@ class Factbase::Inv
74
66
  @fact.to_s
75
67
  end
76
68
 
77
- def method_missing(*args)
69
+ others do |*args|
78
70
  k = args[0].to_s
79
71
  @block.call(k[0..-2], args[1]) if k.end_with?('=')
80
72
  @fact.method_missing(*args)
81
73
  end
82
-
83
- # rubocop:disable Style/OptionalBooleanParameter
84
- def respond_to?(_method, _include_private = false)
85
- # rubocop:enable Style/OptionalBooleanParameter
86
- true
87
- end
88
-
89
- def respond_to_missing?(_method, _include_private = false)
90
- true
91
- end
92
74
  end
93
75
 
94
76
  # Query decorator.
@@ -96,6 +78,8 @@ class Factbase::Inv
96
78
  # This is an internal class, it is not supposed to be instantiated directly.
97
79
  #
98
80
  class Query
81
+ decoor(:query)
82
+
99
83
  def initialize(query, block)
100
84
  @query = query
101
85
  @block = block
@@ -107,9 +91,5 @@ class Factbase::Inv
107
91
  yield Fact.new(f, @block)
108
92
  end
109
93
  end
110
-
111
- def delete!
112
- @query.delete!
113
- end
114
94
  end
115
95
  end
@@ -20,6 +20,7 @@
20
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  # SOFTWARE.
22
22
 
23
+ require 'others'
23
24
  require 'time'
24
25
  require 'loog'
25
26
  require 'tago'
@@ -31,18 +32,18 @@ require_relative 'syntax'
31
32
  # License:: MIT
32
33
  class Factbase::Looged
33
34
  def initialize(fb, loog)
35
+ raise 'The "fb" is nil' if fb.nil?
34
36
  @fb = fb
37
+ raise 'The "loog" is nil' if loog.nil?
35
38
  @loog = loog
36
39
  end
37
40
 
41
+ decoor(:fb)
42
+
38
43
  def dup
39
44
  Factbase::Looged.new(@fb.dup, @loog)
40
45
  end
41
46
 
42
- def size
43
- @fb.size
44
- end
45
-
46
47
  def insert
47
48
  f = @fb.insert
48
49
  @loog.debug("Inserted new fact ##{@fb.size}")
@@ -72,14 +73,6 @@ class Factbase::Looged
72
73
  r
73
74
  end
74
75
 
75
- def export
76
- @fb.export
77
- end
78
-
79
- def import(bytes)
80
- @fb.import(bytes)
81
- end
82
-
83
76
  # Fact decorator.
84
77
  #
85
78
  # This is an internal class, it is not supposed to be instantiated directly.
@@ -92,11 +85,7 @@ class Factbase::Looged
92
85
  @loog = loog
93
86
  end
94
87
 
95
- def to_s
96
- @fact.to_s
97
- end
98
-
99
- def method_missing(*args)
88
+ others do |*args|
100
89
  r = @fact.method_missing(*args)
101
90
  k = args[0].to_s
102
91
  v = args[1]
@@ -106,16 +95,6 @@ class Factbase::Looged
106
95
  @loog.debug("Set '#{k[0..-2]}' to #{s} (#{v.class})") if k.end_with?('=')
107
96
  r
108
97
  end
109
-
110
- # rubocop:disable Style/OptionalBooleanParameter
111
- def respond_to?(_method, _include_private = false)
112
- # rubocop:enable Style/OptionalBooleanParameter
113
- true
114
- end
115
-
116
- def respond_to_missing?(_method, _include_private = false)
117
- true
118
- end
119
98
  end
120
99
 
121
100
  # Query decorator.
data/lib/factbase/pre.rb CHANGED
@@ -21,6 +21,7 @@
21
21
  # SOFTWARE.
22
22
 
23
23
  require 'loog'
24
+ require 'decoor'
24
25
  require_relative '../factbase'
25
26
 
26
27
  # A decorator of a Factbase, that runs a provided block on every +insert+.
@@ -28,7 +29,10 @@ require_relative '../factbase'
28
29
  # Copyright:: Copyright (c) 2024 Yegor Bugayenko
29
30
  # License:: MIT
30
31
  class Factbase::Pre
32
+ decoor(:fb)
33
+
31
34
  def initialize(fb, &block)
35
+ raise 'The "fb" is nil' if fb.nil?
32
36
  @fb = fb
33
37
  @block = block
34
38
  end
@@ -37,29 +41,13 @@ class Factbase::Pre
37
41
  Factbase::Pre.new(@fb.dup, &@block)
38
42
  end
39
43
 
40
- def size
41
- @fb.size
42
- end
43
-
44
44
  def insert
45
45
  f = @fb.insert
46
46
  @block.call(f)
47
47
  f
48
48
  end
49
49
 
50
- def query(query)
51
- @fb.query(query)
52
- end
53
-
54
50
  def txn(this = self, &)
55
51
  @fb.txn(this, &)
56
52
  end
57
-
58
- def export
59
- @fb.export
60
- end
61
-
62
- def import(bytes)
63
- @fb.import(bytes)
64
- end
65
53
  end
@@ -20,6 +20,8 @@
20
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  # SOFTWARE.
22
22
 
23
+ require 'decoor'
24
+ require 'others'
23
25
  require_relative '../factbase'
24
26
  require_relative '../factbase/syntax'
25
27
 
@@ -32,16 +34,21 @@ require_relative '../factbase/syntax'
32
34
  # fb = Factabase::Rules.new(fb, '(exists foo)')
33
35
  # fb.txn do |fbt|
34
36
  # f = fbt.insert
35
- # f.bar = 3
37
+ # f.bar = 3 # No exception here
36
38
  # end # Runtime exception here (transaction won't commit)
37
39
  #
38
40
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
39
41
  # Copyright:: Copyright (c) 2024 Yegor Bugayenko
40
42
  # License:: MIT
41
43
  class Factbase::Rules
44
+ decoor(:fb)
45
+
42
46
  def initialize(fb, rules, check = Check.new(rules), uid: nil)
47
+ raise 'The "fb" is nil' if fb.nil?
43
48
  @fb = fb
49
+ raise 'The "rules" is nil' if rules.nil?
44
50
  @rules = rules
51
+ raise 'The "check" is nil' if check.nil?
45
52
  @check = check
46
53
  @uid = uid
47
54
  end
@@ -50,10 +57,6 @@ class Factbase::Rules
50
57
  Factbase::Rules.new(@fb.dup, @rules, @check, uid: @uid)
51
58
  end
52
59
 
53
- def size
54
- @fb.size
55
- end
56
-
57
60
  def insert
58
61
  Fact.new(@fb.insert, @check)
59
62
  end
@@ -76,14 +79,6 @@ class Factbase::Rules
76
79
  end
77
80
  end
78
81
 
79
- def export
80
- @fb.export
81
- end
82
-
83
- def import(bytes)
84
- @fb.import(bytes)
85
- end
86
-
87
82
  # Fact decorator.
88
83
  #
89
84
  # This is an internal class, it is not supposed to be instantiated directly.
@@ -94,26 +89,12 @@ class Factbase::Rules
94
89
  @check = check
95
90
  end
96
91
 
97
- def to_s
98
- @fact.to_s
99
- end
100
-
101
- def method_missing(*args)
92
+ others do |*args|
102
93
  r = @fact.method_missing(*args)
103
94
  k = args[0].to_s
104
95
  @check.it(@fact) if k.end_with?('=')
105
96
  r
106
97
  end
107
-
108
- # rubocop:disable Style/OptionalBooleanParameter
109
- def respond_to?(_method, _include_private = false)
110
- # rubocop:enable Style/OptionalBooleanParameter
111
- true
112
- end
113
-
114
- def respond_to_missing?(_method, _include_private = false)
115
- true
116
- end
117
98
  end
118
99
 
119
100
  # Query decorator.
@@ -121,25 +102,19 @@ class Factbase::Rules
121
102
  # This is an internal class, it is not supposed to be instantiated directly.
122
103
  #
123
104
  class Query
105
+ decoor(:query)
106
+
124
107
  def initialize(query, check)
125
108
  @query = query
126
109
  @check = check
127
110
  end
128
111
 
129
- def one(params = {})
130
- @query.one(params)
131
- end
132
-
133
112
  def each(params = {})
134
113
  return to_enum(__method__, params) unless block_given?
135
114
  @query.each do |f|
136
115
  yield Fact.new(f, @check)
137
116
  end
138
117
  end
139
-
140
- def delete!
141
- @query.delete!
142
- end
143
118
  end
144
119
 
145
120
  # Check one fact.
data/lib/factbase/tee.rb CHANGED
@@ -20,6 +20,7 @@
20
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  # SOFTWARE.
22
22
 
23
+ require 'others'
23
24
  require_relative '../factbase'
24
25
 
25
26
  # Tee of two facts.
@@ -40,20 +41,13 @@ class Factbase::Tee
40
41
  @fact.to_s
41
42
  end
42
43
 
43
- def method_missing(*args)
44
- return @fact.method_missing(*args) unless args[0].to_s == '[]' && args[1].to_s.start_with?('$')
45
- n = args[1].to_s
46
- n = n[1..] unless @upper.is_a?(Factbase::Tee)
47
- @upper[n]
48
- end
49
-
50
- # rubocop:disable Style/OptionalBooleanParameter
51
- def respond_to?(_method, _include_private = false)
52
- # rubocop:enable Style/OptionalBooleanParameter
53
- true
54
- end
55
-
56
- def respond_to_missing?(_method, _include_private = false)
57
- true
44
+ others do |*args|
45
+ if args[0].to_s == '[]' && args[1].to_s.start_with?('$')
46
+ n = args[1].to_s
47
+ n = n[1..] unless @upper.is_a?(Factbase::Tee)
48
+ @upper[n]
49
+ else
50
+ @fact.method_missing(*args)
51
+ end
58
52
  end
59
53
  end
data/lib/factbase.rb CHANGED
@@ -81,7 +81,7 @@ require 'yaml'
81
81
  # License:: MIT
82
82
  class Factbase
83
83
  # Current version of the gem (changed by .rultor.yml on every release)
84
- VERSION = '0.0.52'
84
+ VERSION = '0.0.53'
85
85
 
86
86
  # An exception that may be thrown in a transaction, to roll it back.
87
87
  class Rollback < StandardError; 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.52
4
+ version: 0.0.53
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-20 00:00:00.000000000 Z
11
+ date: 2024-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backtrace
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: decoor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: json
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +80,20 @@ dependencies:
66
80
  - - "~>"
67
81
  - !ruby/object:Gem::Version
68
82
  version: '1.10'
83
+ - !ruby/object:Gem::Dependency
84
+ name: others
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.0'
69
97
  - !ruby/object:Gem::Dependency
70
98
  name: tago
71
99
  requirement: !ruby/object:Gem::Requirement