factbase 0.0.42 → 0.0.43
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/factbase/to_json.rb +3 -3
- data/lib/factbase/to_xml.rb +3 -3
- data/lib/factbase/to_yaml.rb +3 -3
- data/lib/factbase.rb +1 -1
- data/test/factbase/test_term.rb +22 -0
- data/test/factbase/test_to_xml.rb +0 -1
- data/test/factbase/test_to_yaml.rb +2 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a44a8cee031e25c222a2953ad01a064927c97f57639d494a170223956521a5b3
|
4
|
+
data.tar.gz: fe5ddd0ad80092930b245ab03766f6dc6ea75c77acc3b501daed17a36ff6a793
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fec97a8470185dcfc528154847d84de2130e89bdbff91ed26a37744e536fe4b3b5613c40049c5924ec0f84ad9e11f625a611e346551217c261535dbdbdc02466
|
7
|
+
data.tar.gz: 9a39a69321538139bbb86975434e4dcb184d12fa970db1edf63607cb4bceaf67d69c3ad4559693a633e41577a0b489bc73e8080708cf07d22e0e33daad6ff36c
|
data/lib/factbase/to_json.rb
CHANGED
@@ -21,7 +21,6 @@
|
|
21
21
|
# SOFTWARE.
|
22
22
|
|
23
23
|
require 'json'
|
24
|
-
require 'time'
|
25
24
|
require_relative '../factbase'
|
26
25
|
|
27
26
|
# Factbase to JSON converter.
|
@@ -37,14 +36,15 @@ require_relative '../factbase'
|
|
37
36
|
# License:: MIT
|
38
37
|
class Factbase::ToJSON
|
39
38
|
# Constructor.
|
40
|
-
def initialize(fb)
|
39
|
+
def initialize(fb, sorter = '_id')
|
41
40
|
@fb = fb
|
41
|
+
@sorter = sorter
|
42
42
|
end
|
43
43
|
|
44
44
|
# Convert the entire factbase into JSON.
|
45
45
|
# @return [String] The factbase in JSON format
|
46
46
|
def json
|
47
47
|
maps = Marshal.load(@fb.export)
|
48
|
-
maps.map { |m| m.sort.to_h }.to_json
|
48
|
+
maps.sort_by { |m| m[@sorter] }.map { |m| m.sort.to_h }.to_json
|
49
49
|
end
|
50
50
|
end
|
data/lib/factbase/to_xml.rb
CHANGED
@@ -37,8 +37,9 @@ require_relative '../factbase'
|
|
37
37
|
# License:: MIT
|
38
38
|
class Factbase::ToXML
|
39
39
|
# Constructor.
|
40
|
-
def initialize(fb)
|
40
|
+
def initialize(fb, sorter = '_id')
|
41
41
|
@fb = fb
|
42
|
+
@sorter = sorter
|
42
43
|
end
|
43
44
|
|
44
45
|
# Convert the entire factbase into XML.
|
@@ -48,12 +49,11 @@ class Factbase::ToXML
|
|
48
49
|
maps = Marshal.load(bytes)
|
49
50
|
meta = {
|
50
51
|
version: Factbase::VERSION,
|
51
|
-
dob: Time.now.utc.iso8601,
|
52
52
|
size: bytes.size
|
53
53
|
}
|
54
54
|
Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml|
|
55
55
|
xml.fb(meta) do
|
56
|
-
maps.each do |m|
|
56
|
+
maps.sort_by { |m| m[@sorter] }.each do |m|
|
57
57
|
xml.f_ do
|
58
58
|
m.sort.to_h.each do |k, vv|
|
59
59
|
if vv.is_a?(Array)
|
data/lib/factbase/to_yaml.rb
CHANGED
@@ -21,7 +21,6 @@
|
|
21
21
|
# SOFTWARE.
|
22
22
|
|
23
23
|
require 'yaml'
|
24
|
-
require 'time'
|
25
24
|
require_relative '../factbase'
|
26
25
|
|
27
26
|
# Factbase to YAML converter.
|
@@ -37,14 +36,15 @@ require_relative '../factbase'
|
|
37
36
|
# License:: MIT
|
38
37
|
class Factbase::ToYAML
|
39
38
|
# Constructor.
|
40
|
-
def initialize(fb)
|
39
|
+
def initialize(fb, sorter = '_id')
|
41
40
|
@fb = fb
|
41
|
+
@sorter = sorter
|
42
42
|
end
|
43
43
|
|
44
44
|
# Convert the entire factbase into YAML.
|
45
45
|
# @return [String] The factbase in YAML format
|
46
46
|
def yaml
|
47
47
|
maps = Marshal.load(@fb.export)
|
48
|
-
YAML.dump({ 'facts' => maps.map { |m| m.sort.to_h } })
|
48
|
+
YAML.dump({ 'facts' => maps.sort_by { |m| m[@sorter] }.map { |m| m.sort.to_h } })
|
49
49
|
end
|
50
50
|
end
|
data/lib/factbase.rb
CHANGED
@@ -79,7 +79,7 @@ require 'yaml'
|
|
79
79
|
# License:: MIT
|
80
80
|
class Factbase
|
81
81
|
# Current version of the gem (changed by .rultor.yml on every release)
|
82
|
-
VERSION = '0.0.
|
82
|
+
VERSION = '0.0.43'
|
83
83
|
|
84
84
|
# An exception that may be thrown in a transaction, to roll it back.
|
85
85
|
class Rollback < StandardError; end
|
data/test/factbase/test_term.rb
CHANGED
@@ -22,6 +22,7 @@
|
|
22
22
|
|
23
23
|
require 'minitest/autorun'
|
24
24
|
require_relative '../../lib/factbase/term'
|
25
|
+
require_relative '../../lib/factbase/syntax'
|
25
26
|
|
26
27
|
# Term test.
|
27
28
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
@@ -227,6 +228,27 @@ class TestTerm < Minitest::Test
|
|
227
228
|
assert(msg.include?('at (at)'), msg)
|
228
229
|
end
|
229
230
|
|
231
|
+
def test_aggregation
|
232
|
+
maps = [
|
233
|
+
{ 'x' => 1, 'y' => 0, 'z' => 4 },
|
234
|
+
{ 'x' => 2, 'y' => 42, 'z' => 3 },
|
235
|
+
{ 'x' => 3, 'y' => 42, 'z' => 5 },
|
236
|
+
{ 'x' => 4, 'y' => 42, 'z' => 2 },
|
237
|
+
{ 'x' => 5, 'y' => 42, 'z' => 1 },
|
238
|
+
{ 'x' => 8, 'y' => 0, 'z' => 6 }
|
239
|
+
]
|
240
|
+
{
|
241
|
+
'(eq x (agg (eq y 42) (min x)))' => '(eq x 2)',
|
242
|
+
'(eq z (agg (eq y 0) (max z)))' => '(eq x 8)',
|
243
|
+
'(eq x (agg (and (eq y 42) (gt z 1)) (max x)))' => '(eq x 4)',
|
244
|
+
'(and (eq x (agg (eq y 42) (min x))) (eq z 3))' => '(eq x 2)'
|
245
|
+
}.each do |q, r|
|
246
|
+
t = Factbase::Syntax.new(q).to_term
|
247
|
+
f = maps.find { |m| t.evaluate(fact(m), maps) }
|
248
|
+
assert(Factbase::Syntax.new(r).to_term.evaluate(fact(f), []))
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
230
252
|
private
|
231
253
|
|
232
254
|
def fact(map = {})
|
@@ -33,9 +33,10 @@ class TestToYAML < Minitest::Test
|
|
33
33
|
def test_simple_rendering
|
34
34
|
fb = Factbase.new
|
35
35
|
f = fb.insert
|
36
|
+
f._id = 1
|
36
37
|
f.foo = 42
|
37
38
|
f.foo = 256
|
38
|
-
fb.insert
|
39
|
+
fb.insert._id = 2
|
39
40
|
to = Factbase::ToYAML.new(fb)
|
40
41
|
yaml = YAML.load(to.yaml)
|
41
42
|
assert_equal(2, yaml['facts'].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.
|
4
|
+
version: 0.0.43
|
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-
|
11
|
+
date: 2024-06-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|