fbe 0.0.38 → 0.0.40

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: e69702483c25c55333a0391946414e8204e5116c47af9ce6c76736f30ac60e09
4
- data.tar.gz: 5d868159c91bd6c58d6b6be8c5ba25c1138c0191cf5b915044a49b170342a36e
3
+ metadata.gz: c5738119a9d73b0ec3e019726bb057059059d0bd5fe08815b0290477902aa4c9
4
+ data.tar.gz: f2a54bd36e5672e060d9066fe3aa67077e52dc705da9a2cc3f01002dd9ef1bd4
5
5
  SHA512:
6
- metadata.gz: 0c7ed04c82fe5f4c1fe28a127113ab65bc539db0079bb097ebb9979ba2cb521f37a4f5b6ee16aab51f8eac2e67e3da2bbba2f28372218a4a17de6c767514edf4
7
- data.tar.gz: 4dc676859c6a144bd405808180a63c23bebd61423dc6d009a752a983c4267786b170e6d50758f98896adeb699d775ed75d9978dbf3dc90d0dbd56faee9502a15
6
+ metadata.gz: c394e6be7d4a376681ba87e308b28b21187454f68725c2fd3774dda934c0fa9a7caadced6e982da9c8f79c6b276abdf4fc2d26e64e325e801e8a0487ddb7dcc2
7
+ data.tar.gz: 7815c260f71e1b77fee5a61faaafc41bd5a98843ef250209fb267fc0dc3cd81b466a257ac7452df664bf5e859ab1ae78cc7e23d3e9bc6ad58d24aa33c57750be
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ # MIT License
4
+ #
5
+ # Copyright (c) 2024 Zerocracy
6
+ #
7
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ # of this software and associated documentation files (the "Software"), to deal
9
+ # in the Software without restriction, including without limitation the rights
10
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ # copies of the Software, and to permit persons to whom the Software is
12
+ # furnished to do so, subject to the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be included in all
15
+ # copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ # SOFTWARE.
24
+
25
+ require_relative '../fbe'
26
+ require_relative 'fb'
27
+
28
+ # Overwrite a property in the fact.
29
+ #
30
+ # If the property doesn't exist in the fact, it will be added. If it does
31
+ # exist, it will be removed (the entire fact will be destroyed, new fact
32
+ # created, and property set).
33
+ #
34
+ # @param [Factbase::Fact] fact The fact to modify
35
+ # @param [String] property The name of the property to set
36
+ # @param [Any] vqlue The value to set
37
+ def Fbe.overwrite(fact, property, value, fb: Fbe.fb)
38
+ before = {}
39
+ fact.all_properties.each do |prop|
40
+ before[prop.to_s] = fact[prop]
41
+ end
42
+ fb.query("(and #{before.map { |k, vv| vv.is_a?(Array) ? '' : " (eq #{k} #{vv})" }.join})").delete!
43
+ n = fb.insert
44
+ before[property.to_s] = value
45
+ before.each do |k, vv|
46
+ next if k.start_with?('_')
47
+ vv = [vv] unless vv.is_a?(Array)
48
+ vv.each do |v|
49
+ n.send("#{k}=", v)
50
+ end
51
+ end
52
+ end
data/lib/fbe/regularly.rb CHANGED
@@ -25,11 +25,9 @@
25
25
  require_relative '../fbe'
26
26
  require_relative 'fb'
27
27
 
28
- def Fbe.regularly(area, days, interval, fb: Fbe.fb, judge: $judge, loog: $loog, &)
29
- pmp = fb.query("(and (eq what 'pmp') (eq area '#{area}') (exists #{days}))").each.to_a.first
30
- days = pmp.nil? ? 28 : pmp[days].first
31
- since = Time.now - (days * 24 * 60 * 60)
32
- interval = pmp.nil? ? 7 : pmp[interval].first
28
+ def Fbe.regularly(area, p_every_days, p_since_days = nil, fb: Fbe.fb, judge: $judge, loog: $loog, &)
29
+ pmp = fb.query("(and (eq what 'pmp') (eq area '#{area}') (exists #{p_every_days}))").each.to_a.first
30
+ interval = pmp.nil? ? 7 : pmp[p_every_days].first
33
31
  unless fb.query(
34
32
  "(and
35
33
  (eq what '#{judge}')
@@ -41,6 +39,10 @@ def Fbe.regularly(area, days, interval, fb: Fbe.fb, judge: $judge, loog: $loog,
41
39
  f = fb.insert
42
40
  f.what = judge
43
41
  f.when = Time.now
44
- f.since = since
42
+ unless p_since_days.nil?
43
+ days = pmp.nil? ? 28 : pmp[p_since_days].first
44
+ since = Time.now - (days * 24 * 60 * 60)
45
+ f.since = since
46
+ end
45
47
  yield f
46
48
  end
data/lib/fbe.rb CHANGED
@@ -27,5 +27,5 @@
27
27
  # License:: MIT
28
28
  module Fbe
29
29
  # Current version of the gem (changed by .rultor.yml on every release)
30
- VERSION = '0.0.38'
30
+ VERSION = '0.0.40'
31
31
  end
@@ -23,6 +23,7 @@
23
23
  # SOFTWARE.
24
24
 
25
25
  require 'minitest/autorun'
26
+ require 'loog'
26
27
  require_relative '../test__helper'
27
28
  require_relative '../../lib/fbe/award'
28
29
 
@@ -58,7 +59,8 @@ class TestAward < Minitest::Test
58
59
  (set b2 (if (lt b2 at_least) b2 0))
59
60
  (set b2 (between b2 3 120))
60
61
  (give b2 "for holding the bug open for too long (${days} days)"))
61
- '
62
+ ',
63
+ judge: '', global: {}, loog: Loog::NULL, options: nil
62
64
  )
63
65
  b = a.bill(hours: 10)
64
66
  assert(b.points <= 100)
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ # MIT License
4
+ #
5
+ # Copyright (c) 2024 Zerocracy
6
+ #
7
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ # of this software and associated documentation files (the "Software"), to deal
9
+ # in the Software without restriction, including without limitation the rights
10
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ # copies of the Software, and to permit persons to whom the Software is
12
+ # furnished to do so, subject to the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be included in all
15
+ # copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ # SOFTWARE.
24
+
25
+ require 'minitest/autorun'
26
+ require 'factbase'
27
+ require_relative '../test__helper'
28
+ require_relative '../../lib/fbe/overwrite'
29
+
30
+ # Test.
31
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
32
+ # Copyright:: Copyright (c) 2024 Zerocracy
33
+ # License:: MIT
34
+ class TestOverwrite < Minitest::Test
35
+ def test_simple_overwrite
36
+ fb = Factbase.new
37
+ f = fb.insert
38
+ f.foo = 42
39
+ f.bar = 'hey'
40
+ f.many = 3
41
+ f.many = 3.14
42
+ Fbe.overwrite(f, :foo, 55, fb:)
43
+ assert_equal(55, fb.query('(always)').each.to_a.first['foo'].first)
44
+ assert_equal('hey', fb.query('(always)').each.to_a.first['bar'].first)
45
+ assert_equal(2, fb.query('(always)').each.to_a.first['many'].size)
46
+ end
47
+
48
+ def test_simple_insert
49
+ fb = Factbase.new
50
+ f = fb.insert
51
+ Fbe.overwrite(f, :foo, 42, fb:)
52
+ assert_equal(42, fb.query('(always)').each.to_a.first['foo'].first)
53
+ end
54
+ end
@@ -38,7 +38,7 @@ class TestRegularly < Minitest::Test
38
38
  loog = Loog::NULL
39
39
  judge = 'test'
40
40
  2.times do
41
- Fbe.regularly('pmp', 'days', 'interval', fb:, loog:, judge:) do |f|
41
+ Fbe.regularly('pmp', 'interval', 'days', fb:, loog:, judge:) do |f|
42
42
  f.foo = 42
43
43
  end
44
44
  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.0.38
4
+ version: 0.0.40
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
@@ -233,6 +233,7 @@ files:
233
233
  - lib/fbe/middleware.rb
234
234
  - lib/fbe/middleware/quota.rb
235
235
  - lib/fbe/octo.rb
236
+ - lib/fbe/overwrite.rb
236
237
  - lib/fbe/pmp.rb
237
238
  - lib/fbe/regularly.rb
238
239
  - lib/fbe/sec.rb
@@ -248,6 +249,7 @@ files:
248
249
  - test/fbe/test_issue.rb
249
250
  - test/fbe/test_iterate.rb
250
251
  - test/fbe/test_octo.rb
252
+ - test/fbe/test_overwrite.rb
251
253
  - test/fbe/test_pmp.rb
252
254
  - test/fbe/test_regularly.rb
253
255
  - test/fbe/test_sec.rb