fbe 0.34.0 → 0.34.1
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/fbe/delete.rb +1 -0
- data/lib/fbe/overwrite.rb +12 -4
- data/lib/fbe.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6640546ac78327c9198d84ead54ecb48c08706f015d487ac5ee1e68a33012579
|
4
|
+
data.tar.gz: 4257c989c9af1be8e8c45755df5c182c1feef2eb9e8247578239e08d08d6c175
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3eef26c76c8a03ec95fc92a18ede1fa53a1fb3c89e189d7694d6175ab742750414c437cde293c342c30c2cf82db519119e801eade81fbaa4fb806aeced6ece0f
|
7
|
+
data.tar.gz: 48e608695735e4ffe0af617394b236bb2b82507c7504617a8a810256a6aa74aecb5851d7e72f64e868764461e7331f9744fff2b339e8b8d5a8cce96297b74288
|
data/lib/fbe/delete.rb
CHANGED
@@ -24,6 +24,7 @@ require_relative 'fb'
|
|
24
24
|
# # new_fact will have all properties except 'age' and 'city'
|
25
25
|
def Fbe.delete(fact, *props, fb: Fbe.fb, id: '_id')
|
26
26
|
raise 'The fact is nil' if fact.nil?
|
27
|
+
return if props.all? { |k| fact[k].nil? }
|
27
28
|
i = fact[id]
|
28
29
|
raise "There is no #{id.inspect} in the fact" if i.nil?
|
29
30
|
i = i.first
|
data/lib/fbe/overwrite.rb
CHANGED
@@ -17,7 +17,7 @@ require_relative 'fb'
|
|
17
17
|
#
|
18
18
|
# @param [Factbase::Fact] fact The fact to modify (must have _id property)
|
19
19
|
# @param [String] property The name of the property to set
|
20
|
-
# @param [Any]
|
20
|
+
# @param [Any] values The value to set (can be any type, including array)
|
21
21
|
# @param [Factbase] fb The factbase to use (defaults to Fbe.fb)
|
22
22
|
# @return [nil] Nothing
|
23
23
|
# @raise [RuntimeError] If fact is nil, has no _id, or property is not a String
|
@@ -27,11 +27,19 @@ require_relative 'fb'
|
|
27
27
|
# user = fb.query('(eq login "john")').first
|
28
28
|
# updated_user = Fbe.overwrite(user, 'status', 'active')
|
29
29
|
# # All properties preserved, only 'status' is set to 'active'
|
30
|
-
def Fbe.overwrite(fact, property,
|
30
|
+
def Fbe.overwrite(fact, property, values, fb: Fbe.fb, fid: '_id')
|
31
31
|
raise 'The fact is nil' if fact.nil?
|
32
32
|
raise 'The fb is nil' if fb.nil?
|
33
33
|
raise "The property is not a String but #{property.class} (#{property})" unless property.is_a?(String)
|
34
|
-
|
34
|
+
raise 'The values is nil' if values.nil?
|
35
|
+
values = [values] unless values.is_a?(Array)
|
36
|
+
return fact if !fact[property].nil? && fact[property].one? && values.one? && fact[property].first == values.first
|
37
|
+
if fact[property].nil?
|
38
|
+
values.each do |v|
|
39
|
+
fact.send(:"#{property}=", v)
|
40
|
+
end
|
41
|
+
return
|
42
|
+
end
|
35
43
|
before = {}
|
36
44
|
fact.all_properties.each do |prop|
|
37
45
|
before[prop.to_s] = fact[prop]
|
@@ -41,7 +49,7 @@ def Fbe.overwrite(fact, property, value, fb: Fbe.fb, fid: '_id')
|
|
41
49
|
raise "No facts by #{fid} = #{id}" if fb.query("(eq #{fid} #{id})").delete!.zero?
|
42
50
|
fb.txn do |fbt|
|
43
51
|
n = fbt.insert
|
44
|
-
before[property.to_s] =
|
52
|
+
before[property.to_s] = values
|
45
53
|
before.each do |k, vv|
|
46
54
|
next unless n[k].nil?
|
47
55
|
vv.each do |v|
|
data/lib/fbe.rb
CHANGED