ncore 3.8.0 → 3.9.0
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 +4 -4
- data/CHANGELOG.md +9 -0
- data/lib/ncore/attributes.rb +19 -14
- data/lib/ncore/base.rb +4 -1
- data/lib/ncore/client.rb +14 -5
- data/lib/ncore/filter_attributes.rb +43 -0
- data/lib/ncore/singleton_base.rb +3 -0
- data/lib/ncore/util.rb +0 -13
- data/lib/ncore/version.rb +1 -1
- data/lib/ncore.rb +1 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b9823810517052d731b6290cf93b9bd942f25164aed98940860be7c37b7514b5
|
4
|
+
data.tar.gz: 851945716245d8308d5b14a7fc17afb4207ea25f4dff049779ab8e9f2d1a5a3e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 02103dd4eb28433b6311192c37f727e31708a2d5b4ccd2c46888d13a661f6916c906dbd90ad42e03f00592ab6c267fd46d560c69636070a6ee7ddf50c4f4c037
|
7
|
+
data.tar.gz: ee2d1391f5042222d448aebb3ef96f521eb535d3d0e1d23f6bb715bd2cf836f64d6d8a72527d95efd0af05a2881556111000acb5e65082fa8289f605a90ed51d
|
data/CHANGELOG.md
CHANGED
data/lib/ncore/attributes.rb
CHANGED
@@ -11,25 +11,22 @@ module NCore
|
|
11
11
|
# attr(:name, ...)
|
12
12
|
# adds: obj.name => raw json type
|
13
13
|
# obj.name? => bool
|
14
|
-
def attr(*attrs)
|
14
|
+
def attr(*attrs, predicate: true)
|
15
15
|
attrs.each do |attr|
|
16
16
|
check_existing_method(attr)
|
17
17
|
class_eval <<-AR, __FILE__, __LINE__+1
|
18
18
|
def #{attr}
|
19
19
|
self[:#{attr}]
|
20
20
|
end
|
21
|
-
|
22
|
-
def #{attr}?
|
23
|
-
!! self[:#{attr}]
|
24
|
-
end
|
25
21
|
AR
|
22
|
+
attr_boolean :"#{attr}?" if predicate
|
26
23
|
end
|
27
24
|
end
|
28
25
|
|
29
26
|
# attr_datetime(:updated_at, ...)
|
30
27
|
# adds: obj.updated_at => Time, or raw json type if not parseable
|
31
28
|
# obj.updated_at? => bool
|
32
|
-
def attr_datetime(*attrs)
|
29
|
+
def attr_datetime(*attrs, predicate: true)
|
33
30
|
attrs.each do |attr|
|
34
31
|
check_existing_method(attr)
|
35
32
|
class_eval <<-AD, __FILE__, __LINE__+1
|
@@ -45,18 +42,15 @@ module NCore
|
|
45
42
|
rescue ArgumentError, TypeError
|
46
43
|
self[:#{attr}]
|
47
44
|
end
|
48
|
-
|
49
|
-
def #{attr}?
|
50
|
-
!! self[:#{attr}]
|
51
|
-
end
|
52
45
|
AD
|
46
|
+
attr_boolean :"#{attr}?" if predicate
|
53
47
|
end
|
54
48
|
end
|
55
49
|
|
56
50
|
# attr_decimal(:amount, ...)
|
57
51
|
# adds: obj.amount => BigMoney if String, else raw json type
|
58
52
|
# obj.amount? => bool
|
59
|
-
def attr_decimal(*attrs)
|
53
|
+
def attr_decimal(*attrs, predicate: true)
|
60
54
|
attrs.each do |attr|
|
61
55
|
check_existing_method(attr)
|
62
56
|
class_eval <<-AD, __FILE__, __LINE__+1
|
@@ -68,11 +62,22 @@ module NCore
|
|
68
62
|
self[:#{attr}]
|
69
63
|
end
|
70
64
|
end
|
65
|
+
AD
|
66
|
+
attr_boolean :"#{attr}?" if predicate
|
67
|
+
end
|
68
|
+
end
|
71
69
|
|
72
|
-
|
73
|
-
|
70
|
+
# attr_boolean(:active, :active?, ...)
|
71
|
+
# adds: obj.active
|
72
|
+
# adds: obj.active? - in attrs hash, this looks for the key :active, not :active?
|
73
|
+
def attr_boolean(*attrs)
|
74
|
+
attrs.each do |attr|
|
75
|
+
check_existing_method(attr)
|
76
|
+
class_eval <<-AB, __FILE__, __LINE__+1
|
77
|
+
def #{attr}
|
78
|
+
!! self[:#{attr.to_s.sub(/\?$/,'')}]
|
74
79
|
end
|
75
|
-
|
80
|
+
AB
|
76
81
|
end
|
77
82
|
end
|
78
83
|
|
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.
|
92
|
-
|
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
|
data/lib/ncore/singleton_base.rb
CHANGED
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
data/lib/ncore.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.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-
|
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
|
@@ -142,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
142
143
|
- !ruby/object:Gem::Version
|
143
144
|
version: '0'
|
144
145
|
requirements: []
|
145
|
-
rubygems_version: 3.
|
146
|
+
rubygems_version: 3.5.3
|
146
147
|
signing_key:
|
147
148
|
specification_version: 4
|
148
149
|
summary: NCore - Gem for building REST API clients
|