ncore 3.3.3 → 3.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +20 -0
- data/LICENSE +1 -1
- data/example/lib/my_api/rails/railtie.rb +6 -1
- data/lib/ncore/base.rb +1 -0
- data/lib/ncore/client_cache.rb +3 -2
- data/lib/ncore/exceptions.rb +26 -7
- data/lib/ncore/methods/all.rb +1 -1
- 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
- data/ncore.gemspec +1 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e05865527c77bbb27e9a70c0b880db847160b8904fa7c0693dac8e84be15870f
|
4
|
+
data.tar.gz: f10b8e34df3e7a95d2994e533c45d70671f5ea479e585ac7b3ff89f8ceea9226
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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,7 +1,12 @@
|
|
1
1
|
module MyApi
|
2
2
|
class Railtie < Rails::Railtie
|
3
3
|
|
4
|
-
config.
|
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
data/lib/ncore/client_cache.rb
CHANGED
@@ -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
|
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/methods/all.rb
CHANGED
@@ -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
|
15
|
+
coll << factory({data: hash, metadata: parsed[:metadata]}, creds)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
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 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
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', '<
|
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.
|
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:
|
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: '
|
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: '
|
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.
|
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
|