ncore 3.4.4 → 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: 37764b440a06ae592f8c0b536e431a83ade55ebf27503e591325561876acd1de
4
- data.tar.gz: dd35be93d3d788b55ac6404db24dadc805cee91a87b42485347dd2ea707dee3a
3
+ metadata.gz: f96f627fc2c860f1a647ac69f9c165319c6a79b4d5ddd2b9885e470d44f01e06
4
+ data.tar.gz: 40497aeaee34ffc1b63ac3018b80ce0422800c0451acee3b3f3acfbe7495b920
5
5
  SHA512:
6
- metadata.gz: 2b4a3cec14d91cea9efb6fa947362b9098b212a46102977564060a53b666eff93bcaf1c298e959039597974a729355b92661c4dddd72d03d9353e2e0a249392f
7
- data.tar.gz: d0255d70bba9e5735373b9af7f22f5348736273cd42aedf03d961ba4e33ff121bd6248efe9cc1df4c6630628154b73ed1315152a9d55c51d8ada6309e18b699a
6
+ metadata.gz: 565bbd2f26a065bcb4bb6eb8f15515109db6ae0ebd4a388a9ea1ae18050d5462c14c15178806f3927e98079c52f9fb091c7cdec659e212ecb796128737b569c5
7
+ data.tar.gz: ab02acdb71d0fbc5006ef2bc071449f5cd3b1525e8a321b46c3b22c64aad3b99e6ea17fb6bcd0fb2a455d908885fdf4263ee6508779208e42607fcaf26563477
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
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
+
1
8
  #### 3.4.4
2
9
 
3
10
  - Improve keepalive handling
@@ -96,6 +103,10 @@ Other changes
96
103
  - #i18n_scope, config via Api.i18n_scope=
97
104
  - #cache_key, #cache_version, #cache_key_with_version
98
105
 
106
+ #### 2.3.3
107
+
108
+ - Improve keepalive handling
109
+
99
110
  #### 2.3.2
100
111
 
101
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
@@ -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.4'
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.4
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-04-26 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