ncore 3.3.4 → 3.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/ncore/base.rb +1 -0
- data/lib/ncore/exceptions.rb +26 -7
- data/lib/ncore/singleton_base.rb +1 -0
- data/lib/ncore/version.rb +1 -1
- data/lib/ncore/wait.rb +27 -0
- data/lib/ncore.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c66806c855a5d52a9461e2bc48542dff6b5f9d7628c5bc3a850dbd3a99fdef11
|
4
|
+
data.tar.gz: eeee6c280d80ab935925e883c39d493b8d9dafa39c4d1c6019055781ecf6ce77
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c9d20b236e6dd742ee5863a6bcfff5908993354cef3944ba1d17c930278400df01099ac957d40421bd63d2c7384cadfe8414126d14abe5471b97350d1f3e2b3
|
7
|
+
data.tar.gz: da4473efcb0e5796d9eedf65b0edf1e438c3e5a67a813f0d69f62770e95dbd0cf2e4473349a5e560d030e513c532f07d8d9fb815151c35ded21586547e5ee6de
|
data/CHANGELOG.md
CHANGED
data/lib/ncore/base.rb
CHANGED
data/lib/ncore/exceptions.rb
CHANGED
@@ -15,22 +15,41 @@ module NCore
|
|
15
15
|
class RecordNotFound < Error ; end
|
16
16
|
class UnsavedObjectError < Error ; end
|
17
17
|
|
18
|
-
class
|
18
|
+
class RecordError < Error
|
19
19
|
attr_reader :object
|
20
20
|
|
21
|
-
def initialize(object)
|
21
|
+
def initialize(object, msg: nil)
|
22
22
|
@object = object
|
23
|
-
|
24
|
-
cl_name ||= object.class.class_name if object.class.respond_to?(:class_name)
|
25
|
-
cl_name ||= object.name if object.respond_to?(:name)
|
26
|
-
cl_name ||= object.class.name
|
27
|
-
msg = "\#{cl_name} Invalid: \#{object.errors.to_a.join(' ')}"
|
23
|
+
msg ||= "Error on \#{class_name_for(object)}"
|
28
24
|
super msg
|
29
25
|
end
|
30
26
|
|
31
27
|
def errors
|
32
28
|
object&.errors
|
33
29
|
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def class_name_for(object)
|
34
|
+
n = object.class_name if object.respond_to?(:class_name)
|
35
|
+
n ||= object.class.class_name if object.class.respond_to?(:class_name)
|
36
|
+
n ||= object.name if object.respond_to?(:name)
|
37
|
+
n ||= object.class.name
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class RecordInvalid < RecordError
|
42
|
+
def initialize(object)
|
43
|
+
msg = "\#{class_name_for(object)} Invalid: \#{object.errors.to_a.join(' ')}"
|
44
|
+
super object, msg: msg
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class WaitTimeout < RecordError
|
49
|
+
def initialize(object)
|
50
|
+
msg = "Timeout waiting for condition on \#{class_name_for(object)}"
|
51
|
+
super object, msg: msg
|
52
|
+
end
|
34
53
|
end
|
35
54
|
|
36
55
|
class QueryError < Error
|
data/lib/ncore/singleton_base.rb
CHANGED
data/lib/ncore/version.rb
CHANGED
data/lib/ncore/wait.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
module NCore
|
2
|
+
module Wait
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
private
|
6
|
+
|
7
|
+
def wait_for(seconds, &block)
|
8
|
+
return unless seconds
|
9
|
+
seconds = 45 if seconds == true
|
10
|
+
end_by = seconds.seconds.from_now
|
11
|
+
cnt = 0
|
12
|
+
until Time.current > end_by
|
13
|
+
wait = [end_by-Time.current, retry_in(cnt)].min
|
14
|
+
cnt += 1
|
15
|
+
sleep wait
|
16
|
+
reload
|
17
|
+
return true if block.call
|
18
|
+
end
|
19
|
+
raise self.class.module_parent::WaitTimeout, self
|
20
|
+
end
|
21
|
+
|
22
|
+
def retry_in(count)
|
23
|
+
(count**1.7).round + 1
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
data/lib/ncore.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ncore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Notioneer Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-10-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -121,6 +121,7 @@ files:
|
|
121
121
|
- lib/ncore/singleton_base.rb
|
122
122
|
- lib/ncore/util.rb
|
123
123
|
- lib/ncore/version.rb
|
124
|
+
- lib/ncore/wait.rb
|
124
125
|
- ncore.gemspec
|
125
126
|
homepage: https://notioneer.com/
|
126
127
|
licenses:
|