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 +4 -4
- data/lib/fbe/overwrite.rb +1 -0
- data/lib/fbe/repeatedly.rb +50 -0
- data/lib/fbe.rb +1 -1
- data/test/fbe/test_overwrite.rb +5 -5
- data/test/fbe/test_repeatedly.rb +48 -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: 2431cb14f0a8b96e3c7c1478004756c89c736c41e30a83908955883f677f223f
|
4
|
+
data.tar.gz: a60cfd3c3083d2e9b89de82992981737ab6d375c920fa10de7413ba584ec36f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
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,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.
|
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
|