factbase 0.0.55 → 0.0.57
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/factbase/accum.rb +4 -0
- data/lib/factbase/fact.rb +7 -1
- data/lib/factbase/inv.rb +4 -0
- data/lib/factbase/looged.rb +8 -0
- data/lib/factbase/rules.rb +14 -2
- data/lib/factbase/tee.rb +4 -0
- data/lib/factbase.rb +1 -1
- data/test/factbase/test_fact.rb +12 -0
- data/test/factbase/test_query.rb +7 -0
- data/test/factbase/test_rules.rb +8 -0
- data/test/factbase/test_to_xml.rb +0 -2
- 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: fec35b6880c4cfe0224107a19dd60c4b2e9ca6316b87331897b06d339f1e0f39
|
4
|
+
data.tar.gz: c096effe0c1789dae54ad5da35c9ca603f279c55f93597871f0c03846c04e457
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b2b85cf88fe6f5857fd51d5f58989f4ef078829749bf565b41184b15472b6247c9fa9f901848fcdfc0cc2dfe04be32098e43351e887ea546cbc2817171f0d44
|
7
|
+
data.tar.gz: 1d720b58f13c156e8ee1a8c2c81d88f27339a5924fdfac8a362341a6c0324524d540c82ce1fb2df09e05d7ca7c01e5ca77369b8a35861f8aa131f06eb40018be
|
data/lib/factbase/accum.rb
CHANGED
data/lib/factbase/fact.rb
CHANGED
@@ -57,13 +57,19 @@ class Factbase::Fact
|
|
57
57
|
"[ #{@map.map { |k, v| "#{k}: #{v}" }.join(', ')} ]"
|
58
58
|
end
|
59
59
|
|
60
|
+
# Get a list of all props.
|
61
|
+
# @return [Array<String>] List of all props in the fact
|
62
|
+
def all_properties
|
63
|
+
@map.keys
|
64
|
+
end
|
65
|
+
|
60
66
|
# When a method is missing, this method is called.
|
61
67
|
others do |*args|
|
62
68
|
k = args[0].to_s
|
63
69
|
if k.end_with?('=')
|
64
70
|
kk = k[0..-2]
|
65
71
|
raise "Invalid prop name '#{kk}'" unless kk.match?(/^[a-z_][_a-zA-Z0-9]*$/)
|
66
|
-
raise "Prohibited prop name '#{kk}'" if kk
|
72
|
+
raise "Prohibited prop name '#{kk}'" if methods.include?(kk.to_sym)
|
67
73
|
v = args[1]
|
68
74
|
raise "Prop value can't be nil" if v.nil?
|
69
75
|
raise "Prop value can't be empty" if v == ''
|
data/lib/factbase/inv.rb
CHANGED
data/lib/factbase/looged.rb
CHANGED
data/lib/factbase/rules.rb
CHANGED
@@ -89,6 +89,14 @@ class Factbase::Rules
|
|
89
89
|
@check = check
|
90
90
|
end
|
91
91
|
|
92
|
+
def to_s
|
93
|
+
@fact.to_s
|
94
|
+
end
|
95
|
+
|
96
|
+
def all_properties
|
97
|
+
@fact.all_properties
|
98
|
+
end
|
99
|
+
|
92
100
|
others do |*args|
|
93
101
|
r = @fact.method_missing(*args)
|
94
102
|
k = args[0].to_s
|
@@ -142,12 +150,16 @@ class Factbase::Rules
|
|
142
150
|
end
|
143
151
|
|
144
152
|
def it(fact)
|
145
|
-
|
153
|
+
a = fact[@uid]
|
154
|
+
return if a.nil?
|
155
|
+
@facts << a[0] unless @uid.nil?
|
146
156
|
end
|
147
157
|
|
148
158
|
def include?(fact)
|
149
159
|
return true if @uid.nil?
|
150
|
-
|
160
|
+
a = fact[@uid]
|
161
|
+
return true if a.nil?
|
162
|
+
@facts.include?(a[0])
|
151
163
|
end
|
152
164
|
end
|
153
165
|
end
|
data/lib/factbase/tee.rb
CHANGED
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.
|
84
|
+
VERSION = '0.0.57'
|
85
85
|
|
86
86
|
# An exception that may be thrown in a transaction, to roll it back.
|
87
87
|
class Rollback < StandardError; end
|
data/test/factbase/test_fact.rb
CHANGED
@@ -110,4 +110,16 @@ class TestFact < Minitest::Test
|
|
110
110
|
assert_equal(t.utc, f.foo)
|
111
111
|
assert_equal(t.utc.to_s, f.foo.to_s)
|
112
112
|
end
|
113
|
+
|
114
|
+
def test_some_names_are_prohibited
|
115
|
+
f = Factbase::Fact.new(Mutex.new, {})
|
116
|
+
assert_raises { f.to_s = 42 }
|
117
|
+
assert_raises { f.class = 42 }
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_get_all_properties
|
121
|
+
f = Factbase::Fact.new(Mutex.new, {})
|
122
|
+
f.foo = 42
|
123
|
+
assert(f.all_properties.include?('foo'))
|
124
|
+
end
|
113
125
|
end
|
data/test/factbase/test_query.rb
CHANGED
@@ -173,4 +173,11 @@ class TestQuery < Minitest::Test
|
|
173
173
|
maps << { 'foo' => [42] }
|
174
174
|
assert(Factbase::Query.new(maps, Mutex.new, '(as bar (plus xxx 3))').each.to_a[0]['bar'].nil?)
|
175
175
|
end
|
176
|
+
|
177
|
+
def test_get_all_properties
|
178
|
+
maps = []
|
179
|
+
maps << { 'foo' => [42] }
|
180
|
+
f = Factbase::Query.new(maps, Mutex.new, '(always)').each.to_a[0]
|
181
|
+
assert(f.all_properties.include?('foo'))
|
182
|
+
end
|
176
183
|
end
|
data/test/factbase/test_rules.rb
CHANGED
@@ -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,
|
@@ -65,12 +65,10 @@ class TestToXML < Minitest::Test
|
|
65
65
|
f = fb.insert
|
66
66
|
f.type = 1
|
67
67
|
f.f = 2
|
68
|
-
f.class = 3
|
69
68
|
to = Factbase::ToXML.new(fb)
|
70
69
|
xml = Nokogiri::XML.parse(to.xml)
|
71
70
|
assert(!xml.xpath('/fb/f/type').empty?)
|
72
71
|
assert(!xml.xpath('/fb/f/f').empty?)
|
73
|
-
assert(!xml.xpath('/fb/f/class').empty?)
|
74
72
|
end
|
75
73
|
|
76
74
|
def test_show_types_as_attributes
|
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.57
|
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-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: backtrace
|