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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d40e7887e9c6e73b462571ba9ce5d55e53803f49ffd8f75f2599910e66907c14
4
- data.tar.gz: fedeb150bf39faff3b67f160ecca956670da69b5d367951d2835297ef5aa6bd1
3
+ metadata.gz: 6640546ac78327c9198d84ead54ecb48c08706f015d487ac5ee1e68a33012579
4
+ data.tar.gz: 4257c989c9af1be8e8c45755df5c182c1feef2eb9e8247578239e08d08d6c175
5
5
  SHA512:
6
- metadata.gz: 23507c63c45d42a3c1b742f2f3a73a5a57b84a783a23765886a334b2c74dfdbe49818a1023f54c95d0dc368acbc403532646e32275a84544f70f4ac2c27bf257
7
- data.tar.gz: bb4f0ca37ef989a0c52d06608d13b6561ffefe99a5f8e3e3ee4c461936cec91591c063cf9c0c4d88596694fe237ef9aab7e4849bbaa340214db34ee2b7230a97
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] value The value to set (can be any type, including array)
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, value, fb: Fbe.fb, fid: '_id')
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
- return fact if !fact[property].nil? && fact[property].size == 1 && fact[property].first == value
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] = value.is_a?(Array) ? value : [value]
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
@@ -10,5 +10,5 @@
10
10
  # License:: MIT
11
11
  module Fbe
12
12
  # Current version of the gem (changed by +.rultor.yml+ on every release)
13
- VERSION = '0.34.0' unless const_defined?(:VERSION)
13
+ VERSION = '0.34.1' unless const_defined?(:VERSION)
14
14
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fbe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.34.0
4
+ version: 0.34.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko