resource-struct 0.1.0 → 0.2.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/.rubocop.yml +9 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +3 -2
- data/lib/resource_struct/firm_struct.rb +22 -6
- data/lib/resource_struct/loose_struct.rb +22 -6
- data/lib/resource_struct/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f9513a73bc3c6331f8174bd02c30c72fcbc655fb2e00c8d88cb1cd80fa3c60ae
|
4
|
+
data.tar.gz: 3d1355e235d443b74098434f453a482d090790a25f57c65ce8a57f931813863a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88f21e99bce0cf3620cf0644f240176af22bd64f99a51781c293cd407467062cbe784d50274115e4214443801f34d10c79858a27910e9bf54556356e5e95d753
|
7
|
+
data.tar.gz: bfa0b4576f987a5a5a7d39d62abcc7ac4f00fd6f2d27c8bb20d124fbf092914bab0212c8c4987451a86d47e3c06d31ab3452c777f0f25cb29a128e6ca048e3cf
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
resource-struct (0.
|
4
|
+
resource-struct (0.2.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -48,6 +48,7 @@ GEM
|
|
48
48
|
|
49
49
|
PLATFORMS
|
50
50
|
x86_64-darwin-18
|
51
|
+
x86_64-darwin-19
|
51
52
|
|
52
53
|
DEPENDENCIES
|
53
54
|
rake (~> 13.0)
|
@@ -58,4 +59,4 @@ DEPENDENCIES
|
|
58
59
|
rubocop-rspec
|
59
60
|
|
60
61
|
BUNDLED WITH
|
61
|
-
2.
|
62
|
+
2.3.4
|
@@ -29,7 +29,7 @@ module ResourceStruct
|
|
29
29
|
|
30
30
|
def method_missing(name, *args, &blk)
|
31
31
|
return self[name] if ___key?(name)
|
32
|
-
return !!self[
|
32
|
+
return !!self[name[...-1]] if name.end_with?("?")
|
33
33
|
|
34
34
|
super
|
35
35
|
end
|
@@ -55,17 +55,20 @@ module ResourceStruct
|
|
55
55
|
end
|
56
56
|
|
57
57
|
def ==(other)
|
58
|
-
|
58
|
+
other.is_a?(Hash) && ___all_keys_equal(other) ||
|
59
|
+
(other.is_a?(LooseStruct) || other.is_a?(FirmStruct)) && ___all_keys_equal(other.instance_variable_get(:@hash))
|
59
60
|
end
|
60
61
|
|
61
|
-
def
|
62
|
+
def dig(key, *sub_keys)
|
62
63
|
ckey = ___convert_key(key)
|
63
64
|
|
64
65
|
result =
|
65
66
|
if @ro_struct.key?(ckey)
|
66
67
|
@ro_struct[ckey]
|
68
|
+
elsif key.is_a?(String)
|
69
|
+
@ro_struct[ckey] = ___convert_value(@hash[key] || @hash[key.to_sym])
|
67
70
|
else
|
68
|
-
@ro_struct[ckey] = ___convert_value(@hash[ckey])
|
71
|
+
@ro_struct[ckey] = ___convert_value(@hash[key] || @hash[ckey])
|
69
72
|
end
|
70
73
|
|
71
74
|
return result if sub_keys.empty?
|
@@ -76,7 +79,7 @@ module ResourceStruct
|
|
76
79
|
|
77
80
|
result.dig(*sub_keys)
|
78
81
|
end
|
79
|
-
alias
|
82
|
+
alias [] dig
|
80
83
|
|
81
84
|
private
|
82
85
|
|
@@ -92,11 +95,24 @@ module ResourceStruct
|
|
92
95
|
end
|
93
96
|
|
94
97
|
def ___key?(key)
|
95
|
-
@hash.key?(___convert_key(key))
|
98
|
+
@hash.key?(key) || @hash.key?(___convert_key(key))
|
96
99
|
end
|
97
100
|
|
98
101
|
def ___convert_key(key)
|
99
102
|
key.is_a?(::Symbol) ? key.to_s : key
|
100
103
|
end
|
104
|
+
|
105
|
+
def ___all_keys_equal(other)
|
106
|
+
return false unless @hash.count == other.count
|
107
|
+
|
108
|
+
@hash.reduce(true) do |acc, (k, v)|
|
109
|
+
if other.key?(k)
|
110
|
+
acc && other[k] == v
|
111
|
+
else
|
112
|
+
ck = ___convert_key(k)
|
113
|
+
acc && other.key?(ck) && other[ck] == v
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
101
117
|
end
|
102
118
|
end
|
@@ -26,7 +26,7 @@ module ResourceStruct
|
|
26
26
|
|
27
27
|
def method_missing(name, *_args)
|
28
28
|
return self[name] if ___key?(name)
|
29
|
-
return !!self[
|
29
|
+
return !!self[name[...-1]] if name.end_with?("?")
|
30
30
|
|
31
31
|
nil
|
32
32
|
end
|
@@ -52,17 +52,20 @@ module ResourceStruct
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def ==(other)
|
55
|
-
|
55
|
+
other.is_a?(Hash) && ___all_keys_equal(other) ||
|
56
|
+
(other.is_a?(LooseStruct) || other.is_a?(FirmStruct)) && ___all_keys_equal(other.instance_variable_get(:@hash))
|
56
57
|
end
|
57
58
|
|
58
|
-
def
|
59
|
+
def dig(key, *sub_keys)
|
59
60
|
ckey = ___convert_key(key)
|
60
61
|
|
61
62
|
result =
|
62
63
|
if @ro_struct.key?(ckey)
|
63
64
|
@ro_struct[ckey]
|
65
|
+
elsif key.is_a?(String)
|
66
|
+
@ro_struct[ckey] = ___convert_value(@hash[key] || @hash[key.to_sym])
|
64
67
|
else
|
65
|
-
@ro_struct[ckey] = ___convert_value(@hash[ckey])
|
68
|
+
@ro_struct[ckey] = ___convert_value(@hash[key] || @hash[ckey])
|
66
69
|
end
|
67
70
|
|
68
71
|
return result if sub_keys.empty?
|
@@ -73,7 +76,7 @@ module ResourceStruct
|
|
73
76
|
|
74
77
|
result.dig(*sub_keys)
|
75
78
|
end
|
76
|
-
alias
|
79
|
+
alias [] dig
|
77
80
|
|
78
81
|
private
|
79
82
|
|
@@ -89,11 +92,24 @@ module ResourceStruct
|
|
89
92
|
end
|
90
93
|
|
91
94
|
def ___key?(key)
|
92
|
-
@hash.key?(___convert_key(key))
|
95
|
+
@hash.key?(key) || @hash.key?(___convert_key(key))
|
93
96
|
end
|
94
97
|
|
95
98
|
def ___convert_key(key)
|
96
99
|
key.is_a?(::Symbol) ? key.to_s : key
|
97
100
|
end
|
101
|
+
|
102
|
+
def ___all_keys_equal(other)
|
103
|
+
return false unless @hash.count == other.count
|
104
|
+
|
105
|
+
@hash.reduce(true) do |acc, (k, v)|
|
106
|
+
if other.key?(k)
|
107
|
+
acc && other[k] == v
|
108
|
+
else
|
109
|
+
ck = ___convert_key(k)
|
110
|
+
acc && other.key?(ck) && other[ck] == v
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
98
114
|
end
|
99
115
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resource-struct
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Riedler
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-01 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Openstruct like access without all the headaches of Hash method overrides
|
14
14
|
etc...
|
@@ -55,7 +55,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
55
55
|
- !ruby/object:Gem::Version
|
56
56
|
version: '0'
|
57
57
|
requirements: []
|
58
|
-
rubygems_version: 3.1.
|
58
|
+
rubygems_version: 3.1.6
|
59
59
|
signing_key:
|
60
60
|
specification_version: 4
|
61
61
|
summary: Ruby structs for resource responses
|