factbase 0.0.4 → 0.0.5

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: dc21a8440801909645bc06e200ca9b238ab899f6ecd5ef422eec4d082fdbbfaf
4
- data.tar.gz: 05fb34e5249ec11dd0cddcfe74888d89a3343c44afada52926f720c102804321
3
+ metadata.gz: d62cf79f36b50a4a4e447d9596287e62b4a5c5850a74980ec1571cbf6b2db4e2
4
+ data.tar.gz: 8b0ddac1b055b6de0a78e3f96adf04a2132384a75a65b24ae904f3bd9e41c02f
5
5
  SHA512:
6
- metadata.gz: 6c72854f13afe4af7be6a232c12c60025cd9d286559940e96a0ebd9decf748e13e8db4993bffe64f8416d3c03cd20f9a491c06c55434bdba2f53c32edd7d7410
7
- data.tar.gz: e44f1b7c3c83f207ead55e5aed42844eb98dd53ee6ef5241be0e0931cbe7670dc0c6103c002ce6a4a7cbc8818784de6c7f600a7102d91a20a2dcc732a62fc5d7
6
+ metadata.gz: 73c098af9694327477acb8455b5d28d8c208ed3105f6a7273296c6fca7304ef67a7c6707b8db34d3556d2254b3297c2c93236115a9d69c3ae423d02cc84c5e5c
7
+ data.tar.gz: 5b04e6671d7296e398c2fc7e8bbf5d19a0eeca5429fdab09bea857816601e580c2e38985b7ca434648536693940ac81f90cb140596be740b2f770c54f338b0ae
data/.rubocop.yml CHANGED
@@ -45,3 +45,5 @@ Metrics/PerceivedComplexity:
45
45
  Max: 20
46
46
  Layout/EmptyLineAfterGuardClause:
47
47
  Enabled: false
48
+ Naming/MethodParameterName:
49
+ MinNameLength: 2
data/.rultor.yml CHANGED
@@ -31,8 +31,8 @@ release:
31
31
  [[ "${tag}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || exit -1
32
32
  bundle exec rake
33
33
  rm -rf *.gem
34
- sed -i "s/0\.0\.0/${tag}/g" lib/factbase.rb
35
- git add lib/factbase.rb
34
+ sed -i "s/0\.0\.0/${tag}/g" factbase.gemspec
35
+ git add factbase.gemspec
36
36
  git commit -m "version set to ${tag}"
37
37
  gem build factbase.gemspec
38
38
  chmod 0600 ../rubygems.yml
data/factbase.gemspec CHANGED
@@ -22,16 +22,11 @@
22
22
 
23
23
  require 'English'
24
24
 
25
- lib = File.expand_path('lib', __dir__)
26
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
27
-
28
- require_relative 'lib/factbase'
29
-
30
25
  Gem::Specification.new do |s|
31
26
  s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
32
27
  s.required_ruby_version = '>=2.3'
33
28
  s.name = 'factbase'
34
- s.version = Factbase::VERSION
29
+ s.version = '0.0.5'
35
30
  s.license = 'MIT'
36
31
  s.summary = 'Factbase'
37
32
  s.description = 'Fact base in memory and on disc'
data/lib/factbase/fact.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_relative '../factbase'
24
+
23
25
  # Fact.
24
26
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
25
27
  # Copyright:: Copyright (c) 2024 Yegor Bugayenko
@@ -39,6 +41,12 @@ class Factbase::Fact
39
41
  @map[k] << args[1]
40
42
  end
41
43
  nil
44
+ elsif k == '[]'
45
+ kk = args[1].to_s
46
+ @mutex.synchronize do
47
+ @map[kk] = [] if @map[kk].nil?
48
+ end
49
+ @map[kk]
42
50
  else
43
51
  v = @map[k]
44
52
  raise "Can't find '#{k}'" if v.nil?
@@ -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_relative '../factbase'
23
24
  require_relative 'syntax'
24
25
  require_relative 'fact'
25
26
 
@@ -39,8 +40,9 @@ class Factbase::Query
39
40
  def each
40
41
  term = Factbase::Syntax.new(@query).to_term
41
42
  @maps.each do |m|
42
- next unless term.matches?(m)
43
- yield Factbase::Fact.new(@mutex, m)
43
+ f = Factbase::Fact.new(@mutex, m)
44
+ next unless term.matches?(f)
45
+ yield f
44
46
  end
45
47
  end
46
48
 
@@ -0,0 +1,93 @@
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_relative '../factbase'
24
+
25
+ # Spy.
26
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
27
+ # Copyright:: Copyright (c) 2024 Yegor Bugayenko
28
+ # License:: MIT
29
+ class Factbase::Spy
30
+ def initialize(fb, key)
31
+ @fb = fb
32
+ @key = key
33
+ @caught = []
34
+ end
35
+
36
+ def caught_keys
37
+ @caught
38
+ end
39
+
40
+ def query(expr)
41
+ scan(Factbase::Syntax.new(expr).to_term)
42
+ @fb.query(expr)
43
+ end
44
+
45
+ def insert
46
+ SpyFact.new(@fb.insert, @key, @caught)
47
+ end
48
+
49
+ def export
50
+ @fb.export
51
+ end
52
+
53
+ def import(data)
54
+ @fb.import(data)
55
+ end
56
+
57
+ def to_json(opt = nil)
58
+ @fb.to_json(opt)
59
+ end
60
+
61
+ # A fact that is spying.
62
+ class SpyFact
63
+ def initialize(fact, key, caught)
64
+ @fact = fact
65
+ @key = key
66
+ @caught = caught
67
+ end
68
+
69
+ def method_missing(*args)
70
+ @caught << args[1] if args[0].to_s == "#{@key}="
71
+ @fact.method_missing(*args)
72
+ end
73
+
74
+ # rubocop:disable Style/OptionalBooleanParameter
75
+ def respond_to?(method, include_private = false)
76
+ # rubocop:enable Style/OptionalBooleanParameter
77
+ @fact.respond_to?(method, include_private)
78
+ end
79
+
80
+ def respond_to_missing?(method, include_private = false)
81
+ @fact.respond_to_missing?(method, include_private)
82
+ end
83
+ end
84
+
85
+ private
86
+
87
+ def scan(term)
88
+ @caught << term.operands[1] if term.op == :eq && term.operands[0].to_s == @key
89
+ term.operands.each do |o|
90
+ scan(o) if o.is_a?(Factbase::Term)
91
+ end
92
+ end
93
+ end
data/lib/factbase/term.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_relative '../factbase'
23
24
  require_relative 'fact'
24
25
 
25
26
  # Term.
@@ -27,16 +28,18 @@ require_relative 'fact'
27
28
  # Copyright:: Copyright (c) 2024 Yegor Bugayenko
28
29
  # License:: MIT
29
30
  class Factbase::Term
31
+ attr_reader :op, :operands
32
+
30
33
  def initialize(operator, operands)
31
34
  @op = operator
32
35
  @operands = operands
33
36
  end
34
37
 
35
- # Does it match the map?
36
- # @param [Map] The map
38
+ # Does it match the fact?
39
+ # @param [Factbase::Fact] The fact
37
40
  # @return [bool] TRUE if matches
38
- def matches?(map)
39
- send(@op, map)
41
+ def matches?(fact)
42
+ send(@op, fact)
40
43
  end
41
44
 
42
45
  def to_s
@@ -54,62 +57,62 @@ class Factbase::Term
54
57
 
55
58
  private
56
59
 
57
- def nil(_map)
60
+ def nil(_fact)
58
61
  assert_args(0)
59
62
  true
60
63
  end
61
64
 
62
- def not(map)
65
+ def not(fact)
63
66
  assert_args(1)
64
- !@operands[0].matches?(map)
67
+ !@operands[0].matches?(fact)
65
68
  end
66
69
 
67
- def or(map)
70
+ def or(fact)
68
71
  @operands.each do |o|
69
- return true if o.matches?(map)
72
+ return true if o.matches?(fact)
70
73
  end
71
74
  false
72
75
  end
73
76
 
74
- def and(map)
77
+ def and(fact)
75
78
  @operands.each do |o|
76
- return false unless o.matches?(map)
79
+ return false unless o.matches?(fact)
77
80
  end
78
81
  true
79
82
  end
80
83
 
81
- def exists(map)
84
+ def exists(fact)
82
85
  assert_args(1)
83
86
  k = @operands[0].to_s
84
- !map[k].nil?
87
+ !fact[k].empty?
85
88
  end
86
89
 
87
- def absent(map)
90
+ def absent(fact)
88
91
  assert_args(1)
89
92
  k = @operands[0].to_s
90
- map[k].nil?
93
+ fact[k].empty?
91
94
  end
92
95
 
93
- def eq(map)
96
+ def eq(fact)
94
97
  assert_args(2)
95
98
  k = @operands[0].to_s
96
- v = map[k]
97
- return false if v.nil?
99
+ v = fact[k]
100
+ return false if v.empty?
98
101
  v.include?(@operands[1])
99
102
  end
100
103
 
101
- def lt(map)
104
+ def lt(fact)
102
105
  assert_args(2)
103
106
  k = @operands[0].to_s
104
- v = map[k]
105
- return false if v.nil?
107
+ v = fact[k]
108
+ return false if v.empty?
106
109
  v[0] < @operands[1]
107
110
  end
108
111
 
109
- def gt(map)
112
+ def gt(fact)
110
113
  assert_args(2)
111
114
  k = @operands[0].to_s
112
- v = map[k]
115
+ v = fact[k]
113
116
  return false if v.nil?
114
117
  v[0] > @operands[1]
115
118
  end
@@ -0,0 +1,79 @@
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_relative '../factbase'
24
+
25
+ # White list.
26
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
27
+ # Copyright:: Copyright (c) 2024 Yegor Bugayenko
28
+ # License:: MIT
29
+ class Factbase::WhiteList
30
+ def initialize(fb, key, list)
31
+ @fb = fb
32
+ @key = key
33
+ @allowed = list
34
+ end
35
+
36
+ def query(expr)
37
+ @fb.query(expr)
38
+ end
39
+
40
+ def insert
41
+ WhiteFact.new(@fb.insert, @key, @allowed)
42
+ end
43
+
44
+ def export
45
+ @fb.export
46
+ end
47
+
48
+ def import(data)
49
+ @fb.import(data)
50
+ end
51
+
52
+ def to_json(opt = nil)
53
+ @fb.to_json(opt)
54
+ end
55
+
56
+ # A fact that is allows only values from the list.
57
+ class WhiteFact
58
+ def initialize(fact, key, list)
59
+ @fact = fact
60
+ @key = key
61
+ @allowed = list
62
+ end
63
+
64
+ def method_missing(*args)
65
+ raise "#{args[0]} '#{args[1]}' not allowed" if args[0].to_s == "#{@key}=" && !@allowed.include?(args[1])
66
+ @fact.method_missing(*args)
67
+ end
68
+
69
+ # rubocop:disable Style/OptionalBooleanParameter
70
+ def respond_to?(method, include_private = false)
71
+ # rubocop:enable Style/OptionalBooleanParameter
72
+ @fact.respond_to?(method, include_private)
73
+ end
74
+
75
+ def respond_to_missing?(method, include_private = false)
76
+ @fact.respond_to_missing?(method, include_private)
77
+ end
78
+ end
79
+ end
data/lib/factbase.rb CHANGED
@@ -25,9 +25,6 @@
25
25
  # Copyright:: Copyright (c) 2024 Yegor Bugayenko
26
26
  # License:: MIT
27
27
  class Factbase
28
- # Current version of the library and of this class.
29
- VERSION = '0.0.4'
30
-
31
28
  # Constructor.
32
29
  def initialize
33
30
  @maps = []
@@ -37,6 +34,7 @@ class Factbase
37
34
  # Insert a new fact.
38
35
  # @return [Factbase::Fact] The fact just inserted
39
36
  def insert
37
+ require_relative 'factbase/fact'
40
38
  map = {}
41
39
  @mutex.synchronize do
42
40
  f = Factbase::Fact.new(Mutex.new, map)
@@ -62,6 +60,7 @@ class Factbase
62
60
  #
63
61
  # @param [String] query The query to use for selections
64
62
  def query(query)
63
+ require_relative 'factbase/query'
65
64
  Factbase::Query.new(@maps, @mutex, query)
66
65
  end
67
66
 
@@ -81,6 +80,3 @@ class Factbase
81
80
  @maps.to_json
82
81
  end
83
82
  end
84
-
85
- require_relative 'factbase/fact'
86
- require_relative 'factbase/query'
@@ -23,6 +23,7 @@
23
23
 
24
24
  require 'minitest/autorun'
25
25
  require_relative '../../lib/factbase'
26
+ require_relative '../../lib/factbase/fact'
26
27
 
27
28
  # Fact test.
28
29
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
@@ -36,5 +37,6 @@ class TestFact < Minitest::Test
36
37
  assert_equal(42, f.foo)
37
38
  f.foo = 256
38
39
  assert_equal(42, f.foo)
40
+ assert_equal([42, 256], f['foo'])
39
41
  end
40
42
  end
@@ -23,6 +23,7 @@
23
23
 
24
24
  require 'minitest/autorun'
25
25
  require_relative '../../lib/factbase'
26
+ require_relative '../../lib/factbase/query'
26
27
 
27
28
  # Query test.
28
29
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2024 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.
23
+
24
+ require 'minitest/autorun'
25
+ require_relative '../../lib/factbase'
26
+ require_relative '../../lib/factbase/spy'
27
+
28
+ # Spy test.
29
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
30
+ # Copyright:: Copyright (c) 2024 Yegor Bugayenko
31
+ # License:: MIT
32
+ class TestSpy < Minitest::Test
33
+ def test_simple_spying
34
+ fb = Factbase::Spy.new(Factbase.new, 'foo')
35
+ fb.insert.foo = 42
36
+ fb.insert.foo = 'hello'
37
+ fb.query('(eq foo "test")').each do |f|
38
+ assert(f.id.positive?)
39
+ end
40
+ assert_equal(3, fb.caught_keys.size)
41
+ assert(fb.caught_keys.include?('hello'))
42
+ assert(fb.caught_keys.include?(42))
43
+ assert(fb.caught_keys.include?('test'))
44
+ end
45
+ end
@@ -31,38 +31,38 @@ require_relative '../../lib/factbase/term'
31
31
  class TestTerm < Minitest::Test
32
32
  def test_simple_matching
33
33
  t = Factbase::Term.new(:eq, ['foo', 42])
34
- assert(t.matches?({ 'foo' => [42] }))
35
- assert(!t.matches?({ 'foo' => ['Hello!'] }))
36
- assert(!t.matches?({ 'bar' => ['Hello!'] }))
34
+ assert(t.matches?(fact('foo' => [42])))
35
+ assert(!t.matches?(fact('foo' => ['Hello!'])))
36
+ assert(!t.matches?(fact('bar' => ['Hello!'])))
37
37
  end
38
38
 
39
39
  def test_eq_matching
40
40
  t = Factbase::Term.new(:eq, ['foo', 42])
41
- assert(t.matches?({ 'foo' => [10, 5, 6, -8, 'hey', 42, 9, 'fdsf'] }))
42
- assert(!t.matches?({ 'foo' => [100] }))
41
+ assert(t.matches?(fact('foo' => [10, 5, 6, -8, 'hey', 42, 9, 'fdsf'])))
42
+ assert(!t.matches?(fact('foo' => [100])))
43
43
  end
44
44
 
45
45
  def test_lt_matching
46
46
  t = Factbase::Term.new(:lt, ['foo', 42])
47
- assert(t.matches?({ 'foo' => [10] }))
48
- assert(!t.matches?({ 'foo' => [100] }))
47
+ assert(t.matches?(fact('foo' => [10])))
48
+ assert(!t.matches?(fact('foo' => [100])))
49
49
  end
50
50
 
51
51
  def test_gt_matching
52
52
  t = Factbase::Term.new(:gt, ['foo', 42])
53
- assert(t.matches?({ 'foo' => [100] }))
54
- assert(!t.matches?({ 'foo' => [10] }))
53
+ assert(t.matches?(fact('foo' => [100])))
54
+ assert(!t.matches?(fact('foo' => [10])))
55
55
  end
56
56
 
57
57
  def test_not_matching
58
58
  t = Factbase::Term.new(:not, [Factbase::Term.new(:nil, [])])
59
- assert(!t.matches?({ 'foo' => [100] }))
59
+ assert(!t.matches?(fact('foo' => [100])))
60
60
  end
61
61
 
62
62
  def test_not_exists_matching
63
63
  t = Factbase::Term.new(:not, [Factbase::Term.new(:eq, ['foo', 100])])
64
- assert(t.matches?({ 'foo' => [42, 12, -90] }))
65
- assert(!t.matches?({ 'foo' => [100] }))
64
+ assert(t.matches?(fact('foo' => [42, 12, -90])))
65
+ assert(!t.matches?(fact('foo' => [100])))
66
66
  end
67
67
 
68
68
  def test_or_matching
@@ -73,8 +73,14 @@ class TestTerm < Minitest::Test
73
73
  Factbase::Term.new(:eq, ['bar', 5])
74
74
  ]
75
75
  )
76
- assert(t.matches?({ 'foo' => [4] }))
77
- assert(t.matches?({ 'bar' => [5] }))
78
- assert(!t.matches?({ 'bar' => [42] }))
76
+ assert(t.matches?(fact('foo' => [4])))
77
+ assert(t.matches?(fact('bar' => [5])))
78
+ assert(!t.matches?(fact('bar' => [42])))
79
+ end
80
+
81
+ private
82
+
83
+ def fact(map)
84
+ Factbase::Fact.new(Mutex.new, map)
79
85
  end
80
86
  end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2024 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.
23
+
24
+ require 'minitest/autorun'
25
+ require_relative '../../lib/factbase'
26
+ require_relative '../../lib/factbase/white_list'
27
+
28
+ # WhiteList test.
29
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
30
+ # Copyright:: Copyright (c) 2024 Yegor Bugayenko
31
+ # License:: MIT
32
+ class TestWhiteList < Minitest::Test
33
+ def test_simple_white_listing
34
+ fb = Factbase::WhiteList.new(Factbase.new, 'foo', ['hello'])
35
+ fb.insert.foo = 'hello'
36
+ assert_raises do
37
+ fb.insert.foo = 42
38
+ end
39
+ end
40
+ 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.4
4
+ version: 0.0.5
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-10 00:00:00.000000000 Z
11
+ date: 2024-05-11 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Fact base in memory and on disc
14
14
  email: yegor256@gmail.com
@@ -41,13 +41,17 @@ files:
41
41
  - lib/factbase.rb
42
42
  - lib/factbase/fact.rb
43
43
  - lib/factbase/query.rb
44
+ - lib/factbase/spy.rb
44
45
  - lib/factbase/syntax.rb
45
46
  - lib/factbase/term.rb
47
+ - lib/factbase/white_list.rb
46
48
  - renovate.json
47
49
  - test/factbase/test_fact.rb
48
50
  - test/factbase/test_query.rb
51
+ - test/factbase/test_spy.rb
49
52
  - test/factbase/test_syntax.rb
50
53
  - test/factbase/test_term.rb
54
+ - test/factbase/test_white_list.rb
51
55
  - test/test__helper.rb
52
56
  - test/test_factbase.rb
53
57
  homepage: http://github.com/yegor256/factbase.rb