ncore 3.8.1 → 3.9.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0b92860b930948dd670a333583cd9e20ce4608929eb0c5f968234fe0cace69d3
4
- data.tar.gz: 00e9f32713a037614ff36b322600b95338e23957ed165388c69269a4f9c129df
3
+ metadata.gz: b66817fa03001d9f131ac934006e7923e13a7838119b300cfdab0a724408615b
4
+ data.tar.gz: 25e8291db6f8881a8f4f712c1920d7dd4498ebd192ecb1b35089fecb47afc8c6
5
5
  SHA512:
6
- metadata.gz: fdaddd93c446f6c57d76d490f742d64683e1218f1c9628b2fb6de984d1fc586911746f9f7ffb126e057ffc5b3d57d896bbea3545d1e99276499743b1b884d95b
7
- data.tar.gz: d5af6a87561366c3fc1e92823dd64e281016b8c3b0128edd17998b7ae48879eb590f0b9ca56a6b342baa98784cac7b3aeea8a4418631ae12b0b0f0607ae24eee
6
+ metadata.gz: d8d67db0031bcd320a5a7a62adebea3ce736d7ab64c012fab747d6024db6e2bb106ab8735ad2ebca02ff073cc40e7138060342e9741db0ef3131dffd4bbf97dc
7
+ data.tar.gz: f72ee77da4f993d036a175d0f7474c62583104e8e49bc6cce19f4beefe48f66c71f75b927953eb88aa267fec9dd7b9766c0ab0bbd1208487516439cfef4fc16f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ #### 3.9.1
2
+
3
+ - Fix clearing of memoized association when assoc_id changes
4
+
5
+ #### 3.9.0
6
+
7
+ - Add inspection filter for attributes
8
+ - Fix generation of query params when values are Hashes
9
+
1
10
  #### 3.8.1
2
11
 
3
12
  - Add option to disable some_attr?() definition
@@ -222,9 +222,13 @@ module NCore
222
222
  end
223
223
  P1
224
224
 
225
+ # private def parent_id=(val)
226
+ # if :parent_key changes, clear memoized association
225
227
  class_eval <<-P2, __FILE__, __LINE__+1
226
228
  def #{parent_key}=(v)
227
- @attribs[:#{assoc_name}] = nil unless @attribs[:#{parent_key}] == v
229
+ if @attribs[:#{parent_key}] != v and @attribs[:#{assoc_name}]&.id != v
230
+ @attribs[:#{assoc_name}] = nil
231
+ end
228
232
  @attribs[:#{parent_key}] = v
229
233
  end
230
234
  private :#{parent_key}=
@@ -201,7 +201,7 @@ module NCore
201
201
  args[:data].each do |k,v|
202
202
  if k=='metadata' || k=='errors'
203
203
  @attribs[k] = self.class.interpret_type(v, api_creds)
204
- elsif respond_to?("#{k}=")
204
+ elsif respond_to?("#{k}=", true)
205
205
  send "#{k}=", self.class.interpret_type(v, api_creds)
206
206
  else
207
207
  @attribs[k] = self.class.interpret_type(v, api_creds)
data/lib/ncore/base.rb CHANGED
@@ -1,17 +1,20 @@
1
1
  module NCore
2
2
  module Base
3
3
  extend ActiveSupport::Concern
4
-
4
+
5
5
  included do
6
6
  extend Associations
7
7
  include ActiveModel
8
8
  include Attributes
9
9
  include Client
10
10
  include Client::Cache
11
+ include FilterAttributes
11
12
  include Identity
12
13
  include Lifecycle
13
14
  include Util
14
15
  include Wait
16
+
17
+ self.filter_attributes = []
15
18
  end
16
19
 
17
20
  module ClassMethods
data/lib/ncore/client.rb CHANGED
@@ -88,17 +88,26 @@ module NCore
88
88
 
89
89
  def build_query_string(params)
90
90
  if params.any?
91
- query_string = params.sort.map do |k,v|
92
- if v.is_a?(Array)
91
+ query_string = params.sort.filter_map do |k,v|
92
+ case v
93
+ when Array
93
94
  if v.empty?
94
- "#{k.to_s}[]="
95
+ "#{CGI::escape(k.to_s)}[]"
95
96
  else
96
97
  v.sort.map do |v2|
97
- "#{k.to_s}[]=#{CGI::escape(v2.to_s)}"
98
+ "#{CGI::escape(k.to_s)}[]=#{CGI::escape(v2.to_s)}"
99
+ end.join('&')
100
+ end
101
+ when Hash
102
+ if v.empty?
103
+ nil
104
+ else
105
+ v.sort.map do |k2, v2|
106
+ "#{CGI::escape(k.to_s)}[#{k2}]=#{CGI::escape(v2.to_s)}"
98
107
  end.join('&')
99
108
  end
100
109
  else
101
- "#{k.to_s}=#{CGI::escape(v.to_s)}"
110
+ "#{CGI::escape(k.to_s)}=#{CGI::escape(v.to_s)}"
102
111
  end
103
112
  end.join('&')
104
113
  "?#{query_string}"
@@ -0,0 +1,43 @@
1
+ module NCore
2
+ module FilterAttributes
3
+ extend ActiveSupport::Concern
4
+
5
+ module ClassMethods
6
+
7
+ def filter_attributes
8
+ @filter_attributes || superclass.filter_attributes
9
+ end
10
+
11
+ def filter_attributes=(filter_attributes)
12
+ @inspection_filter = nil
13
+ @filter_attributes = filter_attributes
14
+ end
15
+
16
+ def inspection_filter
17
+ if @filter_attributes
18
+ @inspection_filter ||= ActiveSupport::ParameterFilter.new @filter_attributes
19
+ else
20
+ superclass.inspection_filter
21
+ end
22
+ end
23
+
24
+ end
25
+
26
+
27
+ def inspect
28
+ base = "#{self.class}:0x#{'%016x'%self.object_id} id: #{id.inspect}"
29
+ inspect_chain = Thread.current[:inspect_chain] ||= []
30
+ return "#<#{base}, ...>" if inspect_chain.include? self
31
+ begin
32
+ inspect_chain.push self
33
+ attribs = @attribs.except(:id).each.with_object({}) do |(k,v),h|
34
+ h[k] = v.nil? ? nil : self.class.inspection_filter.filter_param(k,v)
35
+ end
36
+ "#<#{base}, attribs: #{attribs.inspect}, metadata: #{metadata.inspect}>"
37
+ ensure
38
+ inspect_chain.pop
39
+ end
40
+ end
41
+
42
+ end
43
+ end
@@ -7,10 +7,13 @@ module NCore
7
7
  include ActiveModel
8
8
  include Attributes
9
9
  include Client
10
+ include FilterAttributes
10
11
  include Identity
11
12
  include Lifecycle
12
13
  include Util
13
14
  include Wait
15
+
16
+ self.filter_attributes = []
14
17
  end
15
18
 
16
19
  module ClassMethods
data/lib/ncore/util.rb CHANGED
@@ -63,18 +63,5 @@ module NCore
63
63
 
64
64
  delegate :factory, to: :class
65
65
 
66
-
67
- def inspect
68
- base = "#{self.class}:0x#{'%016x'%self.object_id} id: #{id.inspect}"
69
- @@inspect_chain ||= []
70
- return "#<#{base}, ...>" if @@inspect_chain.include? self
71
- begin
72
- @@inspect_chain.push self
73
- "#<#{base}, attribs: #{@attribs.except(:id).inspect}, metadata: #{metadata.inspect}>"
74
- ensure
75
- @@inspect_chain.pop
76
- end
77
- end
78
-
79
66
  end
80
67
  end
data/lib/ncore/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module NCore
2
- VERSION = '3.8.1'
2
+ VERSION = '3.9.1'
3
3
  end
data/lib/ncore.rb CHANGED
@@ -15,6 +15,7 @@ require 'pp'
15
15
  exceptions
16
16
  identity
17
17
  lifecycle
18
+ filter_attributes
18
19
  util
19
20
  wait
20
21
  base
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.8.1
4
+ version: 3.9.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: 2024-02-08 00:00:00.000000000 Z
11
+ date: 2024-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -101,6 +101,7 @@ files:
101
101
  - lib/ncore/collection.rb
102
102
  - lib/ncore/configuration.rb
103
103
  - lib/ncore/exceptions.rb
104
+ - lib/ncore/filter_attributes.rb
104
105
  - lib/ncore/identity.rb
105
106
  - lib/ncore/lifecycle.rb
106
107
  - lib/ncore/methods/all.rb