factbase 0.0.54 → 0.0.56

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: 96802899cf0f4cae545f776183957bf7326ddc3a8476973527b7cc625f7494d0
4
- data.tar.gz: 45a75383175707c8a698bbe16c737ec03e6daf7c1506bb9977122b1ebe262503
3
+ metadata.gz: d26f7abaafccccb51ef4077d66fed7a4a8ef846df2a7d46191d7113b27a2a689
4
+ data.tar.gz: 8d0a64e42a4a695edc7ef5a7958ceb69aa6a965e53778782bd865c49a8752a4f
5
5
  SHA512:
6
- metadata.gz: ae4d3ae2580d55ea253f7b8e86eaf18b72f5a05c62c82c727a8517f8bb8878d44c21c7bb6f90e4cff22bb0a83be68436bd06f4d04aa795f36b7cba406abe3b71
7
- data.tar.gz: 14766601c87755749cdc3806a43f39d331542b4db6c33272ced27982c99d4836dcdc17fcc00f189a6b74f5679a2b23857e08f84871fe4a4142bf96eb55afa398
6
+ metadata.gz: 65c7a43401b8933e212dea979319cc75a0e42349123f0cd98871ee4d1493002b2f280a229820101ef481168c64a2e97333a549036dd3c88dfa3d05b4230d9085
7
+ data.tar.gz: 9106f2c57b7840e95de6a6dba53859f0d0c4e0bea5770b22d558c35894e847145fe0b9d5640d017441baa91be48bcbc4a09cf38ae8390ab9d0efe379b5add37b
@@ -38,7 +38,7 @@ class Factbase::Flatten
38
38
  # @return [Array<HashMap>] The hashmaps, but improved
39
39
  def it
40
40
  @maps
41
- .sort_by { |m| m[@sorter] }
41
+ .sort_by { |m| m[@sorter] || [] }
42
42
  .map { |m| m.sort.to_h }
43
43
  .map { |m| m.transform_values { |v| v.size == 1 ? v[0] : v } }
44
44
  end
@@ -142,12 +142,16 @@ class Factbase::Rules
142
142
  end
143
143
 
144
144
  def it(fact)
145
- @facts << fact.send(@uid) unless @uid.nil?
145
+ a = fact[@uid]
146
+ return if a.nil?
147
+ @facts << a[0] unless @uid.nil?
146
148
  end
147
149
 
148
150
  def include?(fact)
149
151
  return true if @uid.nil?
150
- @facts.include?(fact.send(@uid))
152
+ a = fact[@uid]
153
+ return true if a.nil?
154
+ @facts.include?(a[0])
151
155
  end
152
156
  end
153
157
  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.54'
84
+ VERSION = '0.0.56'
85
85
 
86
86
  # An exception that may be thrown in a transaction, to roll it back.
87
87
  class Rollback < StandardError; end
@@ -214,6 +214,7 @@ class Factbase
214
214
  #
215
215
  # @param [Bytes] bytes Byte array to import
216
216
  def import(bytes)
217
+ raise 'Empty input, cannot load a factbase' if bytes.empty?
217
218
  @maps += Marshal.load(bytes)
218
219
  end
219
220
  end
@@ -36,4 +36,10 @@ class TestFlatten < Minitest::Test
36
36
  assert(42, to[1]['b'])
37
37
  assert(2, to[2]['c'].size)
38
38
  end
39
+
40
+ def test_without_sorter
41
+ maps = [{ 'b' => [42], 'i' => [44] }, { 'a' => 33 }]
42
+ to = Factbase::Flatten.new(maps, 'i').it
43
+ assert(33, to[0]['a'])
44
+ end
39
45
  end
@@ -44,6 +44,14 @@ class TestRules < Minitest::Test
44
44
  end
45
45
  end
46
46
 
47
+ def test_check_with_id
48
+ fb = Factbase::Rules.new(Factbase.new, '(exists foo)', uid: 'id')
49
+ fb.txn do |fbt|
50
+ f = fbt.insert
51
+ f.foo = 42
52
+ end
53
+ end
54
+
47
55
  def test_to_string
48
56
  fb = Factbase::Rules.new(
49
57
  Factbase.new,
@@ -90,6 +90,18 @@ class TestFactbase < Minitest::Test
90
90
  assert_equal(1, f2.query('(eq foo 42)').each.to_a.count)
91
91
  end
92
92
 
93
+ def test_reads_from_empty_file
94
+ fb = Factbase.new
95
+ Tempfile.open do |f|
96
+ File.binwrite(f.path, '')
97
+ assert(
98
+ assert_raises do
99
+ fb.import(File.binread(f.path))
100
+ end.message.include?('cannot load a factbase')
101
+ )
102
+ end
103
+ end
104
+
93
105
  def test_empty_or_not
94
106
  fb = Factbase.new
95
107
  assert_equal(0, fb.size)
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.54
4
+ version: 0.0.56
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-24 00:00:00.000000000 Z
11
+ date: 2024-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backtrace