ncore 3.4.3 → 3.5.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: 6470a812da166c0852f57b34a60f8632ba22359fe84cab9cde7f005e552f12ac
4
- data.tar.gz: 2e5dc6c7998ef95911c8c739ca39142105f73ab59c165383342e086a3755c526
3
+ metadata.gz: f96f627fc2c860f1a647ac69f9c165319c6a79b4d5ddd2b9885e470d44f01e06
4
+ data.tar.gz: 40497aeaee34ffc1b63ac3018b80ce0422800c0451acee3b3f3acfbe7495b920
5
5
  SHA512:
6
- metadata.gz: 551b111c0e2a86b0d0ce3b209001e1bb7307f347fdec2122c62971edd25dd9a2d658def1569c64abda20fd53439e99280571bc706e48bf219e4313aee1b3b093
7
- data.tar.gz: 5c4def6f9020d41f7e3a52504d26c946d9d884952b1cb198f9a4dd8c81552576b9bc5241925e0793b73f5e75856bf6a282d5fe0c3b09b58a69bdf3fc31f2d7f2
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
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014-2022 Notioneer, Inc.
1
+ Copyright (c) 2014-2023 Notioneer, Inc.
2
2
 
3
3
  MIT License
4
4
 
@@ -1,109 +1,148 @@
1
1
  module NCore
2
2
  module Associations
3
3
 
4
- def has_many(assoc, class_name: nil)
5
- assoc = assoc.to_s
6
- klass = class_name || "#{module_name}::#{assoc.camelize.singularize}"
7
- key = "#{attrib_name}_id"
8
- class_eval <<-M1, __FILE__, __LINE__+1
9
- def #{assoc}(params={})
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[:#{key}] = id
20
+ params[:#{parent_key}] = id
15
21
  if cacheable
16
22
  # only cache unfiltered, default api call
17
- @attribs[:#{assoc}] = (!reload && @attribs[:#{assoc}]) || #{klass}.all(params)
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
- M1
23
- class_eval <<-M2, __FILE__, __LINE__+1
24
- def find_#{assoc.singularize}(aid, params={})
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[:#{key}] = id
35
+ params[:#{parent_key}] = id
28
36
  #{klass}.find(aid, params)
29
37
  end
30
- M2
31
- # will always return the object; check .errors? or .valid? to see how it went
32
- class_eval <<-M3, __FILE__, __LINE__+1
33
- def create_#{assoc.singularize}(params={})
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[:#{key}] = id
37
- #{klass}.create(params)
45
+ params[:#{parent_key}] = id
46
+ #{klass}.retrieve(aid, params)
38
47
  end
39
- M3
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 <<-M4, __FILE__, __LINE__+1
42
- def update_#{assoc.singularize}(aid, params={})
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[:#{key}] = id
46
- #{klass}.update(aid, params)
56
+ params[:#{parent_key}] = id
57
+ #{klass}.create(params)
47
58
  end
48
- M4
49
- class_eval <<-M5, __FILE__, __LINE__+1
50
- def create_#{assoc.singularize}!(params={})
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[:#{key}] = id
66
+ params[:#{parent_key}] = id
54
67
  #{klass}.create!(params)
55
68
  end
56
- M5
57
- class_eval <<-M6, __FILE__, __LINE__+1
58
- def update_#{assoc.singularize}!(aid, params={})
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[:#{key}] = id
87
+ params[:#{parent_key}] = id
62
88
  #{klass}.update!(aid, params)
63
89
  end
64
- M6
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 <<-M7, __FILE__, __LINE__+1
67
- def delete_#{assoc.singularize}(aid, params={})
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[:#{key}] = id
98
+ params[:#{parent_key}] = id
71
99
  #{klass}.delete(aid, params)
72
100
  end
73
- M7
74
- class_eval <<-M8, __FILE__, __LINE__+1
75
- def delete_#{assoc.singularize}!(aid, params={})
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[:#{key}] = id
108
+ params[:#{parent_key}] = id
79
109
  #{klass}.delete!(aid, params)
80
110
  end
81
- M8
111
+ D2
82
112
  end
83
113
 
84
- def belongs_to(assoc, class_name: nil)
85
- assoc = assoc.to_s
86
- klass = class_name || "#{module_name}::#{assoc.camelize}"
87
- class_eval <<-M1, __FILE__, __LINE__+1
88
- attr :#{assoc}_id
89
- def #{assoc}(params={})
90
- return nil unless #{assoc}_id
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[:#{assoc}] ||= #{klass}.find(#{assoc}_id, params)
132
+ @attribs[:#{assoc_name}] ||= #{klass}.find(#{parent_key}, params)
95
133
  else
96
- #{klass}.find(#{assoc}_id, params)
134
+ #{klass}.find(#{parent_key}, params)
97
135
  end
98
136
  end
99
- M1
100
- class_eval <<-M2, __FILE__, __LINE__+1
101
- def #{assoc}_id=(v)
102
- @attribs[:#{assoc}] = nil unless @attribs[:#{assoc}_id] == v
103
- @attribs[:#{assoc}_id] = v
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 :#{assoc}_id=
106
- M2
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 #&& e.message =~ /end of file reached/
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, ActiveSupport::LogSubscriber::YELLOW, false)
40
+ msg = color(msg, :yellow)
41
41
  if (200..299).include? http_status
42
- res = color(res, ActiveSupport::LogSubscriber::GREEN, true)
42
+ res = color(res, :green, bold: true)
43
43
  else
44
- res = color(res, ActiveSupport::LogSubscriber::RED, true)
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
@@ -1,3 +1,3 @@
1
1
  module NCore
2
- VERSION = '3.4.3'
2
+ VERSION = '3.5.0'
3
3
  end
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.1'
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.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: 2022-03-27 00:00:00.000000000 Z
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.1'
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.1'
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.2.32
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