ncore 3.8.1 → 3.9.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: 0b92860b930948dd670a333583cd9e20ce4608929eb0c5f968234fe0cace69d3
4
- data.tar.gz: 00e9f32713a037614ff36b322600b95338e23957ed165388c69269a4f9c129df
3
+ metadata.gz: b9823810517052d731b6290cf93b9bd942f25164aed98940860be7c37b7514b5
4
+ data.tar.gz: 851945716245d8308d5b14a7fc17afb4207ea25f4dff049779ab8e9f2d1a5a3e
5
5
  SHA512:
6
- metadata.gz: fdaddd93c446f6c57d76d490f742d64683e1218f1c9628b2fb6de984d1fc586911746f9f7ffb126e057ffc5b3d57d896bbea3545d1e99276499743b1b884d95b
7
- data.tar.gz: d5af6a87561366c3fc1e92823dd64e281016b8c3b0128edd17998b7ae48879eb590f0b9ca56a6b342baa98784cac7b3aeea8a4418631ae12b0b0f0607ae24eee
6
+ metadata.gz: 02103dd4eb28433b6311192c37f727e31708a2d5b4ccd2c46888d13a661f6916c906dbd90ad42e03f00592ab6c267fd46d560c69636070a6ee7ddf50c4f4c037
7
+ data.tar.gz: ee2d1391f5042222d448aebb3ef96f521eb535d3d0e1d23f6bb715bd2cf836f64d6d8a72527d95efd0af05a2881556111000acb5e65082fa8289f605a90ed51d
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ #### 3.9.0
2
+
3
+ - Add inspection filter for attributes
4
+ - Fix generation of query params when values are Hashes
5
+
1
6
  #### 3.8.1
2
7
 
3
8
  - Add option to disable some_attr?() definition
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.0'
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.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: 2024-02-08 00:00:00.000000000 Z
11
+ date: 2024-02-27 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