resource-struct 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +17 -0
- data/Gemfile.lock +1 -1
- data/lib/resource_struct/extensions/indifferent_lookup.rb +21 -6
- data/lib/resource_struct/flex_struct.rb +15 -8
- data/lib/resource_struct/strict_struct.rb +1 -1
- data/lib/resource_struct/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81f9dfcc67f4c1670776860dd53c7d0885eb1b1d53ca7b9bae7202c782cbad85
|
4
|
+
data.tar.gz: ae36515a1e79be8653e2b4497dee9ab5f8d522e740cfcafe93681d946a5e528e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 835d23cd09aa4a26cce6cf30378e749f5eee0a9439501fd1120ee3ac6f77f6adaed05ea688632e23dce09dd7bee8616859176fbc135b2d027c388aa3eec10e1b
|
7
|
+
data.tar.gz: 102bada15cf4151340c2fd95c5927335e19ec9bd637a2e74ba3b1e2193ead54a3a3a5af8d451caf364f0465caf5663079eeeaf72e3b7c7acc7b1ef7c847e3f95
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,22 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.4.0] - 2022-01-09
|
4
|
+
### Feature
|
5
|
+
- Better support for `ArgumentError` on `FlexStruct`
|
6
|
+
|
7
|
+
## [0.3.3] - 2022-01-05
|
8
|
+
### Fix
|
9
|
+
- Support false values correctly, instead of returning nil
|
10
|
+
- Support `respond_to?` properly on `FlexStruct`
|
11
|
+
|
12
|
+
## [0.3.2] - 2022-01-05
|
13
|
+
### Fix
|
14
|
+
- Support for proper marshalling of object
|
15
|
+
|
16
|
+
## [0.3.1] - 2022-01-05
|
17
|
+
### Fix
|
18
|
+
- Support nil meaning empty hash as first argument to `FlexStruct` and `StrictStruct`
|
19
|
+
|
3
20
|
## [0.3.0] - 2022-01-04
|
4
21
|
### Feature
|
5
22
|
- Support for `as_json` and `to_json`
|
data/Gemfile.lock
CHANGED
@@ -16,7 +16,7 @@ module ResourceStruct
|
|
16
16
|
@hash = hash || {}
|
17
17
|
@ro_struct = {}
|
18
18
|
|
19
|
-
raise ::ArgumentError, "first argument must be a Hash, found #{hash.class.name}" unless hash.is_a?(Hash)
|
19
|
+
raise ::ArgumentError, "first argument must be a Hash, found #{@hash.class.name}" unless @hash.is_a?(Hash)
|
20
20
|
end
|
21
21
|
|
22
22
|
def inspect
|
@@ -35,10 +35,12 @@ module ResourceStruct
|
|
35
35
|
result =
|
36
36
|
if @ro_struct.key?(ckey)
|
37
37
|
@ro_struct[ckey]
|
38
|
-
elsif key
|
39
|
-
@ro_struct[ckey] = ___convert_value(@hash[key]
|
40
|
-
|
41
|
-
@ro_struct[ckey] = ___convert_value(@hash[key]
|
38
|
+
elsif @hash.key?(key)
|
39
|
+
@ro_struct[ckey] = ___convert_value(@hash[key])
|
40
|
+
elsif key.is_a?(String) && @hash.key?(key.to_sym)
|
41
|
+
@ro_struct[ckey] = ___convert_value(@hash[key.to_sym])
|
42
|
+
elsif key.is_a?(Symbol) && @hash.key?(key.to_s)
|
43
|
+
@ro_struct[ckey] = ___convert_value(@hash[key.to_s])
|
42
44
|
end
|
43
45
|
|
44
46
|
return result if sub_keys.empty?
|
@@ -51,6 +53,17 @@ module ResourceStruct
|
|
51
53
|
end
|
52
54
|
alias [] dig
|
53
55
|
|
56
|
+
def marshal_dump
|
57
|
+
{
|
58
|
+
data: @hash
|
59
|
+
}
|
60
|
+
end
|
61
|
+
|
62
|
+
def marshal_load(obj)
|
63
|
+
@ro_struct = {}
|
64
|
+
@hash = obj[:data]
|
65
|
+
end
|
66
|
+
|
54
67
|
private
|
55
68
|
|
56
69
|
def ___convert_value(value)
|
@@ -65,7 +78,9 @@ module ResourceStruct
|
|
65
78
|
end
|
66
79
|
|
67
80
|
def ___key?(key)
|
68
|
-
@hash.key?(key) ||
|
81
|
+
@hash.key?(key) ||
|
82
|
+
@hash.key?(___convert_key(key)) ||
|
83
|
+
key.is_a?(String) && @hash.key?(key.to_sym)
|
69
84
|
end
|
70
85
|
|
71
86
|
def ___convert_key(key)
|
@@ -27,24 +27,31 @@ module ResourceStruct
|
|
27
27
|
|
28
28
|
if @hash.key?(key)
|
29
29
|
@hash[key] = value
|
30
|
-
elsif key.is_a?(String)
|
30
|
+
elsif key.is_a?(String) && @hash.key?(key.to_sym)
|
31
31
|
@hash[key.to_sym] = value
|
32
|
+
elsif key.is_a?(Symbol) && @hash.key?(key.to_s)
|
33
|
+
@hash[key.to_s] = value
|
32
34
|
else
|
33
35
|
@hash[key] = value
|
34
36
|
end
|
35
37
|
end
|
36
38
|
|
37
39
|
def method_missing(name, *args)
|
38
|
-
|
39
|
-
|
40
|
-
return !!self[name[...-1]] if name.end_with?("?") && args_length.zero?
|
41
|
-
return self[name[...-1]] = args.first if name.end_with?("=") && args_length == 1
|
40
|
+
if name.end_with?("=")
|
41
|
+
return self[name[...-1]] = args.first if args.length == 1
|
42
42
|
|
43
|
-
|
43
|
+
raise ArgumentError, "expected 1 argument received #{args.length} arguments"
|
44
|
+
elsif name.end_with?("?")
|
45
|
+
return !!self[name[...-1]] if args.empty?
|
46
|
+
elsif args.empty?
|
47
|
+
return self[name]
|
48
|
+
end
|
49
|
+
|
50
|
+
raise ArgumentError, "expected 0 arguments received #{args.length} arguments"
|
44
51
|
end
|
45
52
|
|
46
|
-
def respond_to_missing?(
|
47
|
-
|
53
|
+
def respond_to_missing?(name, include_private = false)
|
54
|
+
___key?(name) || ___key?(name.to_s.chomp("?")) || super
|
48
55
|
end
|
49
56
|
end
|
50
57
|
LooseStruct = FlexStruct
|
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.4.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: 2022-01-
|
11
|
+
date: 2022-01-10 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...
|