ncore 3.5.2 → 3.6.1

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: 8146188f466028c5c5bea61b9a11d6a11f5d4ffe9af24c6f58ae019223b3d4c6
4
- data.tar.gz: 51c9ebd2bdbb07bd4dc9d5685b31d85bb5c272073564325dd747058748a7f1d4
3
+ metadata.gz: 7768ca94332000d27a96d5eef72643b122d592461be7c46bcd46f0d3ac4cfa37
4
+ data.tar.gz: f247238c94a6a94011df71583b7f85f2a04e30b52edf6bbf3c908b06fc5be9ba
5
5
  SHA512:
6
- metadata.gz: b9cef4054143ffc04613bb0156d240723d806f49415e2845c96428617739b512c47dae9924c339ed2f7271692ecf6a8b94a32b0a380b6786968ee4ec677b2c96
7
- data.tar.gz: 2eaa61533b248ce9470f186d95397546040864b289fb3d7c69981aa7fa932b654852a8a74e5818eaabf7e89d3afd5fd38abc0fc28a5fd1e665bf225de2a22d70
6
+ metadata.gz: 896e527a4b7d5dc140dc9b21c51bbb1755488f505fd4815bed349a739d9de170ebb0773786f156857f6a6cd188adf2999982d519a3d9d53762b1a477dd51186f
7
+ data.tar.gz: 43f131a9684c8fde7dc088724c0ed5d4ab64e7b3f7f0ed6e150eddcfadf6e97d88f6335e96108d5b341f4051ace9f8fc5dc0b88371a734deb29381a7e55d574d
data/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ #### 3.6.1
2
+
3
+ - Restore usage of Resource.new(some_attr: 'value')
4
+
5
+ #### 3.6.0
6
+
7
+ - factory() - add :preload option; make available to resource instances
8
+ - Resource.new() - add :preload option
9
+ Hint: the first arg (attribs) must be a hash, not kwarg: `new({id: id})`
10
+ (no longer true as of 3.6.1)
11
+
1
12
  #### 3.5.2
2
13
 
3
14
  - Fix logger=()
@@ -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, options={})
99
99
  @attribs = {}.with_indifferent_access
100
100
  attribs = attribs.dup.with_indifferent_access
101
+ preload = options[:preload].present? ? options[: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),
@@ -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
@@ -5,7 +5,7 @@ module NCore
5
5
  module ClassMethods
6
6
  def find(id, params={})
7
7
  raise(module_parent::RecordNotFound, "Cannot find id=nil") if id.blank?
8
- o = new(id: id)
8
+ o = new({id: id})
9
9
  o.reload(params)
10
10
  end
11
11
 
@@ -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
@@ -1,3 +1,3 @@
1
1
  module NCore
2
- VERSION = '3.5.2'
2
+ VERSION = '3.6.1'
3
3
  end
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.5.2
4
+ version: 3.6.1
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-02-12 00:00:00.000000000 Z
11
+ date: 2023-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel