ncore 3.4.3 → 3.5.0
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 +15 -0
- data/LICENSE +1 -1
- data/lib/ncore/associations.rb +95 -56
- data/lib/ncore/client.rb +2 -2
- data/lib/ncore/rails/log_subscriber.rb +3 -3
- data/lib/ncore/version.rb +1 -1
- data/ncore.gemspec +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f96f627fc2c860f1a647ac69f9c165319c6a79b4d5ddd2b9885e470d44f01e06
|
4
|
+
data.tar.gz: 40497aeaee34ffc1b63ac3018b80ce0422800c0451acee3b3f3acfbe7495b920
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 565bbd2f26a065bcb4bb6eb8f15515109db6ae0ebd4a388a9ea1ae18050d5462c14c15178806f3927e98079c52f9fb091c7cdec659e212ecb796128737b569c5
|
7
|
+
data.tar.gz: ab02acdb71d0fbc5006ef2bc071449f5cd3b1525e8a321b46c3b22c64aad3b99e6ea17fb6bcd0fb2a455d908885fdf4263ee6508779208e42607fcaf26563477
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
#### 3.5.0
|
2
|
+
|
3
|
+
- Allow ActiveModel 7.1
|
4
|
+
- Update LogSubscriber for ActiveSupport 7.1
|
5
|
+
- Associations: add arg :association_key to has_many, belongs_to
|
6
|
+
- Associations: has_many now builds retrieve_{assoc}
|
7
|
+
|
8
|
+
#### 3.4.4
|
9
|
+
|
10
|
+
- Improve keepalive handling
|
11
|
+
|
1
12
|
#### 3.4.3
|
2
13
|
|
3
14
|
- Fix Rails controller reporting of API times
|
@@ -92,6 +103,10 @@ Other changes
|
|
92
103
|
- #i18n_scope, config via Api.i18n_scope=
|
93
104
|
- #cache_key, #cache_version, #cache_key_with_version
|
94
105
|
|
106
|
+
#### 2.3.3
|
107
|
+
|
108
|
+
- Improve keepalive handling
|
109
|
+
|
95
110
|
#### 2.3.2
|
96
111
|
|
97
112
|
- Allow ActiveSupport 7.0
|
data/LICENSE
CHANGED
data/lib/ncore/associations.rb
CHANGED
@@ -1,109 +1,148 @@
|
|
1
1
|
module NCore
|
2
2
|
module Associations
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
# assoc_name - plural association name
|
5
|
+
# :association_key - key used by the association to reference the parent
|
6
|
+
# defaults to `attrib_name+'_id'`
|
7
|
+
# :class_name - Module::Class of the child association, as a string
|
8
|
+
def has_many(assoc_name, association_key: nil, class_name: nil)
|
9
|
+
assoc_name = assoc_name.to_s
|
10
|
+
parent_key = association_key&.to_s || "#{attrib_name}_id"
|
11
|
+
klass = class_name || "#{module_name}::#{assoc_name.camelize.singularize}"
|
12
|
+
|
13
|
+
# def items({})
|
14
|
+
class_eval <<-A1, __FILE__, __LINE__+1
|
15
|
+
def #{assoc_name}(params={})
|
10
16
|
return [] unless id
|
11
17
|
reload = params.delete :reload
|
12
18
|
cacheable = params.except(:credentials, :request).empty?
|
13
19
|
params = parse_request_params(params).reverse_merge credentials: api_creds
|
14
|
-
params[:#{
|
20
|
+
params[:#{parent_key}] = id
|
15
21
|
if cacheable
|
16
22
|
# only cache unfiltered, default api call
|
17
|
-
@attribs[:#{
|
23
|
+
@attribs[:#{assoc_name}] = (!reload && @attribs[:#{assoc_name}]) || #{klass}.all(params)
|
18
24
|
else
|
19
25
|
#{klass}.all(params)
|
20
26
|
end
|
21
27
|
end
|
22
|
-
|
23
|
-
|
24
|
-
|
28
|
+
A1
|
29
|
+
|
30
|
+
# def find_item(id, {})
|
31
|
+
class_eval <<-F1, __FILE__, __LINE__+1
|
32
|
+
def find_#{assoc_name.singularize}(aid, params={})
|
25
33
|
raise UnsavedObjectError unless id
|
26
34
|
params = parse_request_params(params).reverse_merge credentials: api_creds
|
27
|
-
params[:#{
|
35
|
+
params[:#{parent_key}] = id
|
28
36
|
#{klass}.find(aid, params)
|
29
37
|
end
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
38
|
+
F1
|
39
|
+
|
40
|
+
# def retrieve_item(id, {})
|
41
|
+
class_eval <<-F2, __FILE__, __LINE__+1
|
42
|
+
def retrieve_#{assoc_name.singularize}(aid, params={})
|
34
43
|
raise UnsavedObjectError unless id
|
35
44
|
params = parse_request_params(params).reverse_merge credentials: api_creds
|
36
|
-
params[:#{
|
37
|
-
#{klass}.
|
45
|
+
params[:#{parent_key}] = id
|
46
|
+
#{klass}.retrieve(aid, params)
|
38
47
|
end
|
39
|
-
|
48
|
+
F2
|
49
|
+
|
50
|
+
# def create_item({})
|
40
51
|
# will always return the object; check .errors? or .valid? to see how it went
|
41
|
-
class_eval <<-
|
42
|
-
def
|
52
|
+
class_eval <<-C1, __FILE__, __LINE__+1
|
53
|
+
def create_#{assoc_name.singularize}(params={})
|
43
54
|
raise UnsavedObjectError unless id
|
44
55
|
params = parse_request_params(params).reverse_merge credentials: api_creds
|
45
|
-
params[:#{
|
46
|
-
#{klass}.
|
56
|
+
params[:#{parent_key}] = id
|
57
|
+
#{klass}.create(params)
|
47
58
|
end
|
48
|
-
|
49
|
-
|
50
|
-
|
59
|
+
C1
|
60
|
+
|
61
|
+
# def create_item!({})
|
62
|
+
class_eval <<-C2, __FILE__, __LINE__+1
|
63
|
+
def create_#{assoc_name.singularize}!(params={})
|
51
64
|
raise UnsavedObjectError unless id
|
52
65
|
params = parse_request_params(params).reverse_merge credentials: api_creds
|
53
|
-
params[:#{
|
66
|
+
params[:#{parent_key}] = id
|
54
67
|
#{klass}.create!(params)
|
55
68
|
end
|
56
|
-
|
57
|
-
|
58
|
-
|
69
|
+
C2
|
70
|
+
|
71
|
+
# def update_item(id, {})
|
72
|
+
# will always return the object; check .errors? or .valid? to see how it went
|
73
|
+
class_eval <<-U1, __FILE__, __LINE__+1
|
74
|
+
def update_#{assoc_name.singularize}(aid, params={})
|
75
|
+
raise UnsavedObjectError unless id
|
76
|
+
params = parse_request_params(params).reverse_merge credentials: api_creds
|
77
|
+
params[:#{parent_key}] = id
|
78
|
+
#{klass}.update(aid, params)
|
79
|
+
end
|
80
|
+
U1
|
81
|
+
|
82
|
+
# def update_item!(id, {})
|
83
|
+
class_eval <<-U2, __FILE__, __LINE__+1
|
84
|
+
def update_#{assoc_name.singularize}!(aid, params={})
|
59
85
|
raise UnsavedObjectError unless id
|
60
86
|
params = parse_request_params(params).reverse_merge credentials: api_creds
|
61
|
-
params[:#{
|
87
|
+
params[:#{parent_key}] = id
|
62
88
|
#{klass}.update!(aid, params)
|
63
89
|
end
|
64
|
-
|
90
|
+
U2
|
91
|
+
|
92
|
+
# def delete_item(id, {})
|
65
93
|
# will always return the object; check .errors? or .valid? to see how it went
|
66
|
-
class_eval <<-
|
67
|
-
def delete_#{
|
94
|
+
class_eval <<-D1, __FILE__, __LINE__+1
|
95
|
+
def delete_#{assoc_name.singularize}(aid, params={})
|
68
96
|
raise UnsavedObjectError unless id
|
69
97
|
params = parse_request_params(params).reverse_merge credentials: api_creds
|
70
|
-
params[:#{
|
98
|
+
params[:#{parent_key}] = id
|
71
99
|
#{klass}.delete(aid, params)
|
72
100
|
end
|
73
|
-
|
74
|
-
|
75
|
-
|
101
|
+
D1
|
102
|
+
|
103
|
+
# def delete_item!(id, {})
|
104
|
+
class_eval <<-D2, __FILE__, __LINE__+1
|
105
|
+
def delete_#{assoc_name.singularize}!(aid, params={})
|
76
106
|
raise UnsavedObjectError unless id
|
77
107
|
params = parse_request_params(params).reverse_merge credentials: api_creds
|
78
|
-
params[:#{
|
108
|
+
params[:#{parent_key}] = id
|
79
109
|
#{klass}.delete!(aid, params)
|
80
110
|
end
|
81
|
-
|
111
|
+
D2
|
82
112
|
end
|
83
113
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
114
|
+
# assoc_name - singular association name
|
115
|
+
# :association_key - key on this resource used to reference the parent association
|
116
|
+
# defaults to `assoc_name+'_id'`
|
117
|
+
# :class_name - Module::Class of the parent association, as a string
|
118
|
+
def belongs_to(assoc_name, association_key: nil, class_name: nil)
|
119
|
+
assoc_name = assoc_name.to_s
|
120
|
+
parent_key = association_key&.to_s || "#{assoc_name}_id"
|
121
|
+
klass = class_name || "#{module_name}::#{assoc_name.camelize}"
|
122
|
+
|
123
|
+
# attr :parent_id
|
124
|
+
# def parent({})
|
125
|
+
class_eval <<-P1, __FILE__, __LINE__+1
|
126
|
+
attr :#{parent_key}
|
127
|
+
def #{assoc_name}(params={})
|
128
|
+
return nil unless #{parent_key}
|
91
129
|
params = parse_request_params(params).reverse_merge credentials: api_creds
|
92
130
|
if params.except(:credentials, :request).empty?
|
93
131
|
# only cache unfiltered, default api call
|
94
|
-
@attribs[:#{
|
132
|
+
@attribs[:#{assoc_name}] ||= #{klass}.find(#{parent_key}, params)
|
95
133
|
else
|
96
|
-
#{klass}.find(#{
|
134
|
+
#{klass}.find(#{parent_key}, params)
|
97
135
|
end
|
98
136
|
end
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
@attribs[:#{
|
137
|
+
P1
|
138
|
+
|
139
|
+
class_eval <<-P2, __FILE__, __LINE__+1
|
140
|
+
def #{parent_key}=(v)
|
141
|
+
@attribs[:#{assoc_name}] = nil unless @attribs[:#{parent_key}] == v
|
142
|
+
@attribs[:#{parent_key}] = v
|
104
143
|
end
|
105
|
-
private :#{
|
106
|
-
|
144
|
+
private :#{parent_key}=
|
145
|
+
P2
|
107
146
|
end
|
108
147
|
|
109
148
|
end
|
data/lib/ncore/client.rb
CHANGED
@@ -177,9 +177,9 @@ module NCore
|
|
177
177
|
tries += 1
|
178
178
|
response = connection.request rest_opts.except(:url)
|
179
179
|
rescue Excon::Error::Socket, Excon::Errors::SocketError, Excon::Error::Timeout,
|
180
|
-
Errno::EADDRNOTAVAIL => e
|
180
|
+
Errno::EADDRNOTAVAIL, Errno::ECONNRESET => e
|
181
181
|
# retry when keepalive was closed
|
182
|
-
if tries <= 1
|
182
|
+
if tries <= 1
|
183
183
|
retry
|
184
184
|
else
|
185
185
|
raise e
|
@@ -37,11 +37,11 @@ module NCore
|
|
37
37
|
msg = "%s %s" % [http_method, url]
|
38
38
|
res = " -> %d (%.1f ms)" % [http_status, event.duration]
|
39
39
|
|
40
|
-
msg = color(msg,
|
40
|
+
msg = color(msg, :yellow)
|
41
41
|
if (200..299).include? http_status
|
42
|
-
res = color(res,
|
42
|
+
res = color(res, :green, bold: true)
|
43
43
|
else
|
44
|
-
res = color(res,
|
44
|
+
res = color(res, :red, bold: true)
|
45
45
|
end
|
46
46
|
|
47
47
|
if (200..299).include? http_status
|
data/lib/ncore/version.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', '< 7.
|
21
|
+
spec.add_dependency 'activemodel', '>= 5.2', '< 7.2'
|
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.5.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:
|
11
|
+
date: 2023-01-07 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: '7.
|
22
|
+
version: '7.2'
|
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: '7.
|
32
|
+
version: '7.2'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: excon
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -142,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
142
142
|
- !ruby/object:Gem::Version
|
143
143
|
version: '0'
|
144
144
|
requirements: []
|
145
|
-
rubygems_version: 3.
|
145
|
+
rubygems_version: 3.3.26
|
146
146
|
signing_key:
|
147
147
|
specification_version: 4
|
148
148
|
summary: NCore - Gem for building REST API clients
|