File tree Expand file tree Collapse file tree 2 files changed +31
-2
lines changed Expand file tree Collapse file tree 2 files changed +31
-2
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,10 @@ import Foundation
4
4
public typealias JMESArray = [ Any ]
5
5
public typealias JMESObject = [ String : Any ]
6
6
7
+ public protocol JMESPropertyWrapper {
8
+ var anyValue : Any { get }
9
+ }
10
+
7
11
/// Internal representation of a variable
8
12
public enum JMESVariable {
9
13
case null
@@ -60,11 +64,15 @@ public enum JMESVariable {
60
64
default :
61
65
var object : JMESObject = [ : ]
62
66
for child in mirror. children {
63
- guard let label = child. label else {
67
+ guard var label = child. label else {
64
68
self = . null
65
69
return
66
70
}
67
- let unwrapValue = Self . unwrap ( child. value) ?? NSNull ( )
71
+ var unwrapValue = Self . unwrap ( child. value) ?? NSNull ( )
72
+ if let wrapper = unwrapValue as? JMESPropertyWrapper , label. first == " _ " {
73
+ label = String ( label. dropFirst ( ) )
74
+ unwrapValue = Self . unwrap ( wrapper. anyValue) ?? NSNull ( )
75
+ }
68
76
object [ label] = unwrapValue
69
77
}
70
78
self = . object( object)
Original file line number Diff line number Diff line change @@ -93,4 +93,25 @@ final class MirrorTests: XCTestCase {
93
93
let test = TestObject ( d: [ " test " : " one " , " test2 " : " two " , " test3 " : " three " ] )
94
94
self . testInterpreter ( " test2 " , data: test, result: " two " )
95
95
}
96
+
97
+ func testPropertyWrapper( ) {
98
+ @propertyWrapper struct Wrap < T> : JMESPropertyWrapper {
99
+ var value : T
100
+ var customMirror : Mirror { return Mirror ( reflecting: self . value) }
101
+
102
+ init ( wrappedValue: T ) {
103
+ self . value = wrappedValue
104
+ }
105
+ var wrappedValue : T {
106
+ get { return value }
107
+ set { value = newValue }
108
+ }
109
+ var anyValue : Any { return value }
110
+ }
111
+ struct TestObject {
112
+ @Wrap var test : String
113
+ }
114
+ let test = TestObject ( test: " testText " )
115
+ self . testInterpreter ( " test " , data: test, result: " testText " )
116
+ }
96
117
}
You can’t perform that action at this time.
0 commit comments