fbe 0.0.45 → 0.0.46

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e4d0f09b1f8d0778a1de6ea5506c8516fcbfd73fb9f7d36454530291ca937be6
4
- data.tar.gz: 7087a0ead0d76df576fb7c074fa1bb8d5a6bd03224a6134009aafdd74ec1175f
3
+ metadata.gz: 2431cb14f0a8b96e3c7c1478004756c89c736c41e30a83908955883f677f223f
4
+ data.tar.gz: a60cfd3c3083d2e9b89de82992981737ab6d375c920fa10de7413ba584ec36f0
5
5
  SHA512:
6
- metadata.gz: 31b8948603e95f578821f376e4d05ceefaf1ce830509f462f7890d10c170878b847e0724ee4179464ef7cdde9cbd8218ab8ef2ffb90181ec076c8fb46d4b4b70
7
- data.tar.gz: d57fbf933d93fa1c93c495d52868d67f6c755cf6730a7b56aef71875dbcfaea9c9c78bc06789d19a1835d399dac24b22d3fcdcef62fc1ff4ab7bb2986bc2e665
6
+ metadata.gz: ae5a89b06a88acfbde4e41601faad9df89d3155f09f545e8564d2944a18da7c1dfb27a928edfb79beaee51b357cc433bd4fb404542d3e3592305441c2e01a676
7
+ data.tar.gz: ffc6494268796dbe1edb4da92163bf107e84e422944000e233f419adc59842ddf0842012da4b43cd2a7ad6080fa1f0150bcde81c894c78e6fc0188bba80458e7
data/lib/fbe/overwrite.rb CHANGED
@@ -39,6 +39,7 @@ require_relative 'fb'
39
39
  # @param [Any] vqlue The value to set
40
40
  def Fbe.overwrite(fact, property, value, fb: Fbe.fb)
41
41
  raise 'The fact is nil' if fact.nil?
42
+ raise "The property is not a String but #{property.class} (#{property})" unless property.is_a?(String)
42
43
  return if !fact[property].nil? && fact[property].size == 1 && fact[property].first == value
43
44
  before = {}
44
45
  fact.all_properties.each do |prop|
@@ -0,0 +1,50 @@
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
+ # Run the block provided every X hours.
29
+ #
30
+ # @param [String] area The name of the PMP area
31
+ # @param [Integer] p_every_hours How frequently to run, every X hours
32
+ def Fbe.repeatedly(area, p_every_hours, fb: Fbe.fb, judge: $judge, loog: $loog, &)
33
+ pmp = fb.query("(and (eq what 'pmp') (eq area '#{area}') (exists #{p_every_hours}))").each.to_a.first
34
+ hours = pmp.nil? ? 24 : pmp[p_every_hours].first
35
+ unless fb.query(
36
+ "(and
37
+ (eq what '#{judge}')
38
+ (gt when (minus (to_time (env 'TODAY' '#{Time.now.utc.iso8601}')) '#{hours} hours')))"
39
+ ).each.to_a.empty?
40
+ loog.debug("#{$judge} have recently been executed, skipping now")
41
+ return
42
+ end
43
+ f = fb.query("(and (eq what '#{judge}'))").each.to_a.first
44
+ if f.nil?
45
+ f = fb.insert
46
+ f.what = judge
47
+ end
48
+ Fbe.overwrite(f, 'when', Time.now)
49
+ yield f
50
+ 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.45'
30
+ VERSION = '0.0.46'
31
31
  end
@@ -40,7 +40,7 @@ class TestOverwrite < Minitest::Test
40
40
  f.bar = 'hey you друг'
41
41
  f.many = 3
42
42
  f.many = 3.14
43
- Fbe.overwrite(f, :foo, 55, fb:)
43
+ Fbe.overwrite(f, 'foo', 55, fb:)
44
44
  assert_equal(55, fb.query('(always)').each.to_a.first['foo'].first)
45
45
  assert_equal('hey you друг', fb.query('(always)').each.to_a.first['bar'].first)
46
46
  assert_equal(2, fb.query('(always)').each.to_a.first['many'].size)
@@ -52,7 +52,7 @@ class TestOverwrite < Minitest::Test
52
52
  f._id = 1
53
53
  f.foo = 42
54
54
  fb.insert._id = 2
55
- Fbe.overwrite(f, :foo, 42, fb:)
55
+ Fbe.overwrite(f, 'foo', 42, fb:)
56
56
  assert_equal(1, fb.query('(always)').each.to_a.first._id)
57
57
  end
58
58
 
@@ -60,7 +60,7 @@ class TestOverwrite < Minitest::Test
60
60
  fb = Factbase.new
61
61
  f = fb.insert
62
62
  f._id = 1
63
- Fbe.overwrite(f, :foo, 42, fb:)
63
+ Fbe.overwrite(f, 'foo', 42, fb:)
64
64
  assert_equal(42, fb.query('(always)').each.to_a.first['foo'].first)
65
65
  end
66
66
 
@@ -68,7 +68,7 @@ class TestOverwrite < Minitest::Test
68
68
  fb = Factbase.new
69
69
  f = fb.insert
70
70
  assert_raises do
71
- Fbe.overwrite(f, :foo, 42, fb:)
71
+ Fbe.overwrite(f, 'foo', 42, fb:)
72
72
  end
73
73
  end
74
74
 
@@ -81,7 +81,7 @@ class TestOverwrite < Minitest::Test
81
81
  f2._id = 2
82
82
  f3 = fb.insert
83
83
  f3._id = 1
84
- Fbe.overwrite(f3, :foo, 42, fb:)
84
+ Fbe.overwrite(f3, 'foo', 42, fb:)
85
85
  assert_equal(3, fb.size)
86
86
  end
87
87
  end
@@ -0,0 +1,48 @@
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 'loog'
27
+ require 'factbase'
28
+ require_relative '../test__helper'
29
+ require_relative '../../lib/fbe/repeatedly'
30
+
31
+ # Test.
32
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
33
+ # Copyright:: Copyright (c) 2024 Zerocracy
34
+ # License:: MIT
35
+ class TestRepeatedly < Minitest::Test
36
+ def test_simple
37
+ $fb = Factbase.new
38
+ loog = Loog::NULL
39
+ judge = 'test'
40
+ $global = {}
41
+ 3.times do
42
+ Fbe.repeatedly('pmp', 'every_x_hours', loog:, judge:) do |f|
43
+ f.foo = 42
44
+ end
45
+ end
46
+ assert_equal(1, $fb.size)
47
+ end
48
+ 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.45
4
+ version: 0.0.46
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
@@ -237,6 +237,7 @@ files:
237
237
  - lib/fbe/overwrite.rb
238
238
  - lib/fbe/pmp.rb
239
239
  - lib/fbe/regularly.rb
240
+ - lib/fbe/repeatedly.rb
240
241
  - lib/fbe/sec.rb
241
242
  - lib/fbe/unmask_repos.rb
242
243
  - lib/fbe/who.rb
@@ -254,6 +255,7 @@ files:
254
255
  - test/fbe/test_overwrite.rb
255
256
  - test/fbe/test_pmp.rb
256
257
  - test/fbe/test_regularly.rb
258
+ - test/fbe/test_repeatedly.rb
257
259
  - test/fbe/test_sec.rb
258
260
  - test/fbe/test_unmask_repos.rb
259
261
  - test/fbe/test_who.rb