fbe 0.0.45 → 0.0.47
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/fbe/overwrite.rb +1 -0
- data/lib/fbe/repeatedly.rb +51 -0
- data/lib/fbe.rb +1 -1
- data/test/fbe/test_overwrite.rb +5 -5
- data/test/fbe/test_repeatedly.rb +51 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57aa8d066542b79b5a92f0821de21ed2e3252f04ee7e19bd81b80843d5836afb
|
4
|
+
data.tar.gz: de5b70d35d2bbabd444a2f4ffcfcbd5fa93dc84d14396dcc5c2ee755abbc013e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd7ff87c9a4184059d567f50571ba377db46a9c125d5235e1b4d984c09fa631e2d5a976b7ca51ab9f2bd7e87f40d8cfdc502177d17d8b6101d12fb79deb981ea
|
7
|
+
data.tar.gz: eb9fa611678efe4291716afbde519fd7b6be8ff4cd63d1c41bcf4edee78ad9f5b803104a531c2810a21f68438dda7fa41dda0d30227da48e52effc5d9e998efd
|
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,51 @@
|
|
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
|
+
require_relative 'overwrite'
|
28
|
+
|
29
|
+
# Run the block provided every X hours.
|
30
|
+
#
|
31
|
+
# @param [String] area The name of the PMP area
|
32
|
+
# @param [Integer] p_every_hours How frequently to run, every X hours
|
33
|
+
def Fbe.repeatedly(area, p_every_hours, fb: Fbe.fb, judge: $judge, loog: $loog, &)
|
34
|
+
pmp = fb.query("(and (eq what 'pmp') (eq area '#{area}') (exists #{p_every_hours}))").each.to_a.first
|
35
|
+
hours = pmp.nil? ? 24 : pmp[p_every_hours].first
|
36
|
+
unless fb.query(
|
37
|
+
"(and
|
38
|
+
(eq what '#{judge}')
|
39
|
+
(gt when (minus (to_time (env 'TODAY' '#{Time.now.utc.iso8601}')) '#{hours} hours')))"
|
40
|
+
).each.to_a.empty?
|
41
|
+
loog.debug("#{$judge} have recently been executed, skipping now")
|
42
|
+
return
|
43
|
+
end
|
44
|
+
f = fb.query("(and (eq what '#{judge}'))").each.to_a.first
|
45
|
+
if f.nil?
|
46
|
+
f = fb.insert
|
47
|
+
f.what = judge
|
48
|
+
end
|
49
|
+
Fbe.overwrite(f, 'when', Time.now)
|
50
|
+
yield fb.query("(and (eq what '#{judge}'))").each.to_a.first
|
51
|
+
end
|
data/lib/fbe.rb
CHANGED
data/test/fbe/test_overwrite.rb
CHANGED
@@ -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,
|
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,
|
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,
|
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,
|
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,
|
84
|
+
Fbe.overwrite(f3, 'foo', 42, fb:)
|
85
85
|
assert_equal(3, fb.size)
|
86
86
|
end
|
87
87
|
end
|
@@ -0,0 +1,51 @@
|
|
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 'judges/options'
|
29
|
+
require_relative '../test__helper'
|
30
|
+
require_relative '../../lib/fbe/repeatedly'
|
31
|
+
|
32
|
+
# Test.
|
33
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
34
|
+
# Copyright:: Copyright (c) 2024 Zerocracy
|
35
|
+
# License:: MIT
|
36
|
+
class TestRepeatedly < Minitest::Test
|
37
|
+
def test_simple
|
38
|
+
$fb = Factbase.new
|
39
|
+
$loog = Loog::NULL
|
40
|
+
$options = Judges::Options.new
|
41
|
+
judge = 'test'
|
42
|
+
$global = {}
|
43
|
+
3.times do
|
44
|
+
Fbe.repeatedly('pmp', 'every_x_hours', judge:) do |f|
|
45
|
+
f.foo = 42
|
46
|
+
end
|
47
|
+
end
|
48
|
+
assert_equal(1, $fb.size)
|
49
|
+
assert_equal(42, $fb.query('(always)').each.to_a.first.foo)
|
50
|
+
end
|
51
|
+
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.
|
4
|
+
version: 0.0.47
|
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
|