fbe 0.36.1 → 0.37.0

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: b06cd95d05dd6dfa4e79d2c3e128bb3c8bae254dae8abe5842cc59e12adf26f5
4
- data.tar.gz: 626b6720065bfdf41480b3728545963fc2477e5baa7d6e07f404a396b52df9ca
3
+ metadata.gz: b9c4277fcddc577e646187cc3d3743de609385c1021bbd21382d4aaf0056cbd8
4
+ data.tar.gz: 140f785a6b8f9707c916eccc070999d84eeb3eeb7fd78dbe263506601a806632
5
5
  SHA512:
6
- metadata.gz: 9df729eb9a4e4733ccf08c68fa289c2c05da96e3360a285e7432bc7e2ba0a1cbce56e74b5b1c34dc12023eca1395b045af9ad2f8698ce63a7d47ad5ffdd1273e
7
- data.tar.gz: 24fc078561ad2d0a6169a2aebf965325497f8feca78446fcc6c4f6890c3e685c3bae9ba9c2da049dbdd8090b4363ab9b4acdbfa476c8c1a9f6222d6cf7b28910
6
+ metadata.gz: b03e2a36505b3699fa81962ad8534067de0301f21d565a3aef08c0bb3591ab2fec20fcb8fa66204501ea02edfd722de31f87a9b2e293bdf3b924e6c80cb43713
7
+ data.tar.gz: 912f5403cb51c1eec1b9c4fe6014f6f089ca2057fabfb8169e17c349b3a2ff5ed2d072a06e8327a6b6d650ac2b8c0580b58b0cb47ddc61d3bed9e4d0542e0244
data/Gemfile.lock CHANGED
@@ -262,6 +262,7 @@ PLATFORMS
262
262
  x64-mingw-ucrt
263
263
  x86_64-darwin-20
264
264
  x86_64-darwin-21
265
+ x86_64-darwin-23
265
266
  x86_64-linux
266
267
 
267
268
  DEPENDENCIES
data/lib/fbe/octo.rb CHANGED
@@ -44,6 +44,7 @@ def Fbe.octo(options: $options, global: $global, loog: $loog)
44
44
  raise 'The $loog is not set' if loog.nil?
45
45
  global[:octo] ||=
46
46
  begin
47
+ loog.info("Fbe version is #{Fbe::VERSION}")
47
48
  trace = []
48
49
  if options.testing.nil?
49
50
  o = Octokit::Client.new
data/lib/fbe/overwrite.rb CHANGED
@@ -16,8 +16,8 @@ require_relative 'fb'
16
16
  # an exception will be raised.
17
17
  #
18
18
  # @param [Factbase::Fact] fact The fact to modify (must have _id property)
19
- # @param [String] property The name of the property to set
20
- # @param [Any] values The value to set (can be any type, including array)
19
+ # @param [String, Hash] property_or_hash The name of the property to set, or a hash of properties
20
+ # @param [Any] values The value to set (can be any type, including array) - ignored if first param is Hash
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
@@ -25,11 +25,39 @@ require_relative 'fb'
25
25
  # @note If property already has the same single value, no changes are made
26
26
  # @example Update a user's status
27
27
  # user = fb.query('(eq login "john")').first
28
- # updated_user = Fbe.overwrite(user, 'status', 'active')
28
+ # Fbe.overwrite(user, 'status', 'active')
29
29
  # # All properties preserved, only 'status' is set to 'active'
30
- def Fbe.overwrite(fact, property, values, fb: Fbe.fb, fid: '_id')
30
+ # @example Update multiple properties at once
31
+ # user = fb.query('(eq login "john")').first
32
+ # Fbe.overwrite(user, status: 'active', role: 'admin')
33
+ # # All properties preserved, 'status' and 'role' are updated
34
+ def Fbe.overwrite(fact, property_or_hash, values = nil, fb: Fbe.fb, fid: '_id')
31
35
  raise 'The fact is nil' if fact.nil?
32
36
  raise 'The fb is nil' if fb.nil?
37
+ if property_or_hash.is_a?(Hash)
38
+ before = {}
39
+ fact.all_properties.each do |k|
40
+ before[k.to_s] = fact[k]
41
+ end
42
+ property_or_hash.each do |k, v|
43
+ raise "The value for #{k} is nil" if v.nil?
44
+ before[k.to_s] = v.is_a?(Array) ? v : [v]
45
+ end
46
+ id = fact[fid]&.first
47
+ raise "There is no #{fid} in the fact, cannot use Fbe.overwrite" if id.nil?
48
+ raise "No facts by #{fid} = #{id}" if fb.query("(eq #{fid} #{id})").delete!.zero?
49
+ fb.txn do |fbt|
50
+ n = fbt.insert
51
+ before.each do |k, vv|
52
+ next unless n[k].nil?
53
+ vv.each do |v|
54
+ n.send(:"#{k}=", v)
55
+ end
56
+ end
57
+ end
58
+ return
59
+ end
60
+ property = property_or_hash
33
61
  raise "The property is not a String but #{property.class} (#{property})" unless property.is_a?(String)
34
62
  raise 'The values is nil' if values.nil?
35
63
  values = [values] unless values.is_a?(Array)
@@ -41,8 +69,8 @@ def Fbe.overwrite(fact, property, values, fb: Fbe.fb, fid: '_id')
41
69
  return
42
70
  end
43
71
  before = {}
44
- fact.all_properties.each do |prop|
45
- before[prop.to_s] = fact[prop]
72
+ fact.all_properties.each do |k|
73
+ before[k.to_s] = fact[k]
46
74
  end
47
75
  id = fact[fid]&.first
48
76
  raise "There is no #{fid} in the fact, cannot use Fbe.overwrite" if id.nil?
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.36.1' unless const_defined?(:VERSION)
13
+ VERSION = '0.37.0' 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.36.1
4
+ version: 0.37.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko