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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 36ef02739c4a1da72bcddc653c521e617947618f18819df4cf03d5e83695c7bd
4
- data.tar.gz: fb2363f1754bb367126b871faeaaa0327869166f276715dbde1ec9cea698f41a
3
+ metadata.gz: c66806c855a5d52a9461e2bc48542dff6b5f9d7628c5bc3a850dbd3a99fdef11
4
+ data.tar.gz: eeee6c280d80ab935925e883c39d493b8d9dafa39c4d1c6019055781ecf6ce77
5
5
  SHA512:
6
- metadata.gz: d5f6e466021e4ddfdd378ebc381e515931861a51cd3df4c1340de887f044f47ffe8721a0a94f6c3fb4e59c44eeb78abd94a21e6682ec8ce999072b74e7fa3d3c
7
- data.tar.gz: 195dc54e8e8414819ceef4d0714ac1118cf9bae7fc03143019c18d8fa5fe4d800b8850a9ded557667d85a970329dc9589ee2e5363ceb3546d43bfcf90d433349
6
+ metadata.gz: 9c9d20b236e6dd742ee5863a6bcfff5908993354cef3944ba1d17c930278400df01099ac957d40421bd63d2c7384cadfe8414126d14abe5471b97350d1f3e2b3
7
+ data.tar.gz: da4473efcb0e5796d9eedf65b0edf1e438c3e5a67a813f0d69f62770e95dbd0cf2e4473349a5e560d030e513c532f07d8d9fb815151c35ded21586547e5ee6de
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ #### 3.4.0
2
+
3
+ - Add SomeResource#wait_for and WaitTimeout
4
+
1
5
  #### 3.3.4
2
6
 
3
7
  - Fix :cache option on Ruby 3.0
data/lib/ncore/base.rb CHANGED
@@ -11,6 +11,7 @@ module NCore
11
11
  include Identity
12
12
  include Lifecycle
13
13
  include Util
14
+ include Wait
14
15
  end
15
16
 
16
17
  module ClassMethods
@@ -15,22 +15,41 @@ module NCore
15
15
  class RecordNotFound < Error ; end
16
16
  class UnsavedObjectError < Error ; end
17
17
 
18
- class RecordInvalid < Error
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
- cl_name = object.class_name if object.respond_to?(:class_name)
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
@@ -10,6 +10,7 @@ module NCore
10
10
  include Identity
11
11
  include Lifecycle
12
12
  include Util
13
+ include Wait
13
14
  end
14
15
 
15
16
  module ClassMethods
data/lib/ncore/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module NCore
2
- VERSION = '3.3.4'
2
+ VERSION = '3.4.0'
3
3
  end
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
@@ -16,6 +16,7 @@ require 'pp'
16
16
  identity
17
17
  lifecycle
18
18
  util
19
+ wait
19
20
  base
20
21
  singleton_base
21
22
  ).each do |f|
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.3.4
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-07-22 00:00:00.000000000 Z
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: