ncore 3.5.1 → 3.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/example/lib/my_api/rails/log_subscriber.rb +1 -1
- data/example/lib/my_api/rails/railtie.rb +4 -0
- data/lib/ncore/attributes.rb +6 -1
- data/lib/ncore/client.rb +14 -14
- data/lib/ncore/methods/delete.rb +1 -1
- data/lib/ncore/methods/find.rb +1 -1
- data/lib/ncore/methods/update.rb +1 -1
- data/lib/ncore/rails/active_model.rb +1 -5
- data/lib/ncore/util.rb +6 -3
- data/lib/ncore/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c03f37d348b71840fb1b026e3de31ef6da22ddf18bb74a203c2d8a358c58c5af
|
4
|
+
data.tar.gz: ac03fd561267e2e2b9c85aa27055ccf175aab111dc1da27e7e3d17c88c5f67b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4d425431577a921e17a900b0acd1f7f002708f848b8ced1e5a21b4670d7718c144772ad685ae836cb269a230a4c102ae8cc41a775be4c3ce4af9185d3557d57
|
7
|
+
data.tar.gz: e4ced0c42b03d3c39e01dba00b8f59473a20318e3d7c33aa2218f3577675164d4c1a0c34a582e3a3922262295fdfe130a6b537c2d54d811502c9a8f0d096f64f
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
#### 3.6.0
|
2
|
+
|
3
|
+
- factory() - add :preload option; make available to resource instances
|
4
|
+
- Resource.new() - add :preload option
|
5
|
+
Hint: the first arg (attribs) must be a hash, not kwarg: `new({id: id})`
|
6
|
+
|
7
|
+
#### 3.5.2
|
8
|
+
|
9
|
+
- Fix logger=()
|
10
|
+
|
1
11
|
#### 3.5.1
|
2
12
|
|
3
13
|
- Preserve 'metadata' and 'errors' keys as attributes when inside a standard
|
data/lib/ncore/attributes.rb
CHANGED
@@ -95,12 +95,17 @@ module NCore
|
|
95
95
|
attr_accessor :metadata, :errors
|
96
96
|
|
97
97
|
|
98
|
-
def initialize(attribs={}, api_creds=nil)
|
98
|
+
def initialize(attribs={}, api_creds=nil, preload: {})
|
99
99
|
@attribs = {}.with_indifferent_access
|
100
100
|
attribs = attribs.dup.with_indifferent_access
|
101
|
+
preload = preload.present? ? preload.dup.with_indifferent_access : nil
|
101
102
|
creds_attr = attribs.delete(:credentials)
|
102
103
|
@api_creds = api_creds || creds_attr
|
103
104
|
|
105
|
+
if preload
|
106
|
+
load(data: preload.delete(:data) || preload.except(:credentials, :metadata, :errors))
|
107
|
+
end
|
108
|
+
|
104
109
|
load(
|
105
110
|
metadata: attribs.delete(:metadata),
|
106
111
|
errors: attribs.delete(:errors),
|
data/lib/ncore/client.rb
CHANGED
@@ -314,13 +314,13 @@ module NCore
|
|
314
314
|
|
315
315
|
def debug_request(rest_opts)
|
316
316
|
return unless logger.debug?
|
317
|
-
logger <<
|
318
|
-
#{'-=- '*18}
|
319
|
-
REQUEST:
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
DBG
|
317
|
+
logger << <<~DBG
|
318
|
+
#{'-=- '*18}
|
319
|
+
REQUEST:
|
320
|
+
#{rest_opts[:method].to_s.upcase} #{rest_opts[:url]}
|
321
|
+
#{rest_opts[:headers].map{|h,d| "#{h}: #{d}"}.join("\n ")}
|
322
|
+
#{rest_opts[:body] || 'nil'}
|
323
|
+
DBG
|
324
324
|
end
|
325
325
|
|
326
326
|
def debug_response(response)
|
@@ -330,13 +330,13 @@ DBG
|
|
330
330
|
else
|
331
331
|
json = JSON.parse(response.body||'', symbolize_names: false) rescue response.body
|
332
332
|
end
|
333
|
-
logger <<
|
334
|
-
RESPONSE:
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
#{'-=- '*18}
|
339
|
-
DBG
|
333
|
+
logger << <<~DBG
|
334
|
+
RESPONSE:
|
335
|
+
#{response.headers['Status']} | #{response.headers['Content-Type']} | #{response.body.size} bytes
|
336
|
+
#{response.headers.except('Status', 'Connection', 'Content-Type').map{|h,d| "#{h}: #{d}"}.join("\n ")}
|
337
|
+
#{json.pretty_inspect.split("\n").join("\n ")}
|
338
|
+
#{'-=- '*18}
|
339
|
+
DBG
|
340
340
|
end
|
341
341
|
|
342
342
|
end # ClassMethods
|
data/lib/ncore/methods/delete.rb
CHANGED
@@ -14,7 +14,7 @@ module NCore
|
|
14
14
|
# always returns a new object; check .errors? or .valid? to see how it went
|
15
15
|
def delete(id, params={})
|
16
16
|
raise(module_parent::RecordNotFound, "Cannot delete id=nil") if id.blank?
|
17
|
-
obj = new(id: id)
|
17
|
+
obj = new({id: id})
|
18
18
|
obj.delete(params)
|
19
19
|
obj
|
20
20
|
end
|
data/lib/ncore/methods/find.rb
CHANGED
data/lib/ncore/methods/update.rb
CHANGED
@@ -14,7 +14,7 @@ module NCore
|
|
14
14
|
# always returns a new object; check .errors? or .valid? to see how it went
|
15
15
|
def update(id, attribs)
|
16
16
|
raise(module_parent::RecordNotFound, "Cannot update id=nil") if id.blank?
|
17
|
-
obj = new(id: id)
|
17
|
+
obj = new({id: id})
|
18
18
|
obj.update attribs
|
19
19
|
obj
|
20
20
|
end
|
data/lib/ncore/util.rb
CHANGED
@@ -38,11 +38,11 @@ module NCore
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
-
def factory(parsed, api_creds)
|
41
|
+
def factory(parsed, api_creds, preload: nil)
|
42
42
|
if key = (parsed[:data] || parsed)[:object]
|
43
|
-
discover_class(key, self).new(parsed, api_creds)
|
43
|
+
discover_class(key, self).new(parsed, api_creds, preload: preload)
|
44
44
|
else
|
45
|
-
new(parsed, api_creds)
|
45
|
+
new(parsed, api_creds, preload: preload)
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
@@ -61,6 +61,9 @@ module NCore
|
|
61
61
|
end
|
62
62
|
|
63
63
|
|
64
|
+
delegate :factory, to: :class
|
65
|
+
|
66
|
+
|
64
67
|
def inspect
|
65
68
|
base = "#{self.class}:0x#{'%016x'%self.object_id} id: #{id.inspect}"
|
66
69
|
@@inspect_chain ||= []
|
data/lib/ncore/version.rb
CHANGED
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.6.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: 2023-
|
11
|
+
date: 2023-02-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|