ncore 3.3.3 → 3.4.2

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: c1bfad3aa6f47ff4917335016f0dc43e51617e68b932e064b50bc5fefa84c51d
4
- data.tar.gz: d7a5385d7a62e4429e192ed032da3a205f5d74aaddc8e7961a9b19c52f413f6c
3
+ metadata.gz: e05865527c77bbb27e9a70c0b880db847160b8904fa7c0693dac8e84be15870f
4
+ data.tar.gz: f10b8e34df3e7a95d2994e533c45d70671f5ea479e585ac7b3ff89f8ceea9226
5
5
  SHA512:
6
- metadata.gz: e3bc26138793e56edf190fd010486a2e3e14e9559326d55251e2992ad518dc0c091523d23f27d2a21dc2351f9cadf4e8dc6e50e444ab5d183e158837702d41ce
7
- data.tar.gz: cc000c1c0c60d559527080aae6d152b26b0281816fdb49d83b22c2b9f44f5f337c23dff0ecaabaa83efa7fdb6e7ff75ad371d47317e15502fc26db3ea88c001a
6
+ metadata.gz: 82dbca21c895a10441d08fd7390af765d397966ec90d528f7caf988d8bc9485b5f128ba6c766361c90fbb8eb1ddc47525a7d27366f29e29a3a7dcb552e811b0f
7
+ data.tar.gz: 0f9971e5d56859937c5b21e0dcacdfdeacab3049e327bf727ff28c9e47ec13ee7c36ab7f5b55786924508fb6ccca56187080b79d82bb98019e1eb8c71b0aa60b
data/CHANGELOG.md CHANGED
@@ -1,3 +1,19 @@
1
+ #### 3.4.2
2
+
3
+ - Fix SomeResource.all when payload includes 'data' attribute
4
+
5
+ #### 3.4.1
6
+
7
+ - Allow ActiveModel 7.0
8
+
9
+ #### 3.4.0
10
+
11
+ - Add SomeResource#wait_for and WaitTimeout
12
+
13
+ #### 3.3.4
14
+
15
+ - Fix :cache option on Ruby 3.0
16
+
1
17
  #### 3.3.3
2
18
 
3
19
  - Handle recursion in #inspect
@@ -72,6 +88,10 @@ Other changes
72
88
  - #i18n_scope, config via Api.i18n_scope=
73
89
  - #cache_key, #cache_version, #cache_key_with_version
74
90
 
91
+ #### 2.3.2
92
+
93
+ - Allow ActiveSupport 7.0
94
+
75
95
  #### 2.3.1
76
96
 
77
97
  - Allow ActiveModel 6.1
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014-2021 Notioneer, Inc.
1
+ Copyright (c) 2014-2022 Notioneer, Inc.
2
2
 
3
3
  MIT License
4
4
 
@@ -1,7 +1,12 @@
1
1
  module MyApi
2
2
  class Railtie < Rails::Railtie
3
3
 
4
- config.after_initialize do
4
+ config.action_dispatch.rescue_responses.merge!(
5
+ 'MyApi::RecordInvalid' => :unprocessable_entity, # 422
6
+ 'MyApi::RecordNotFound' => :not_found, # 404
7
+ )
8
+
9
+ initializer "my_api.cache_store" do |app|
5
10
  MyApi::Api.cache_store = Rails.cache
6
11
  end
7
12
 
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
@@ -6,11 +6,12 @@ module NCore
6
6
 
7
7
  private
8
8
 
9
+ # only caches GET requests with 200..299, 409, 422 responses
9
10
  # cache_opts: true
10
11
  # use *::Api.cache_store
11
12
  # cache_opts: {...}
12
13
  # use: *::Api.cache_store, with options: {...}
13
- # hint: add force: true execute the query and rewrite the cache
14
+ # hint: add force: true to execute the query and rewrite the cache
14
15
  # cache_opts: Store.new
15
16
  # use Store.new as-is
16
17
  def execute_request(req, cache_opts=nil)
@@ -26,7 +27,7 @@ module NCore
26
27
  end
27
28
 
28
29
  if store && req[:method] == :get
29
- store.fetch request_cache_key(req.slice(:url, :headers)), cache_opts do
30
+ store.fetch request_cache_key(**req.slice(:url, :headers)), cache_opts do
30
31
  super
31
32
  end
32
33
  else
@@ -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
@@ -12,7 +12,7 @@ module NCore
12
12
  Collection.new.tap do |coll|
13
13
  coll.metadata = parsed[:metadata]
14
14
  parsed[:data].each do |hash|
15
- coll << factory(hash.merge(metadata: parsed[:metadata]), creds)
15
+ coll << factory({data: hash, metadata: parsed[:metadata]}, creds)
16
16
  end
17
17
  end
18
18
  end
@@ -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.3'
2
+ VERSION = '3.4.2'
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 self 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|
data/ncore.gemspec CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency 'activemodel', '>= 5.2', '< 6.2'
21
+ spec.add_dependency 'activemodel', '>= 5.2', '< 7.1'
22
22
  spec.add_dependency 'excon', '~> 0.32'
23
23
 
24
24
  spec.add_development_dependency "bundler"
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.3
4
+ version: 3.4.2
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-16 00:00:00.000000000 Z
11
+ date: 2022-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '5.2'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '6.2'
22
+ version: '7.1'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '5.2'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '6.2'
32
+ version: '7.1'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: excon
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -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:
@@ -141,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
142
  - !ruby/object:Gem::Version
142
143
  version: '0'
143
144
  requirements: []
144
- rubygems_version: 3.2.15
145
+ rubygems_version: 3.2.22
145
146
  signing_key:
146
147
  specification_version: 4
147
148
  summary: NCore - Gem for building REST API clients