Skip to content

Commit

Permalink
Add support for dictionary mirrored(value:) (#9)
Browse files Browse the repository at this point in the history
* Add support for dictionary mirrored(value:)

* Handle case where there aren't any children
  • Loading branch information
mike-metaplex authored Oct 28, 2022
1 parent 05657fa commit f467c6a
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions Sources/Beet/Beets/Enums.swift
Original file line number Diff line number Diff line change
Expand Up @@ -240,20 +240,25 @@ public class DataEnum<E: ConstructableWithDiscriminator>: FixableBeet {

public func mirrored(value: Any) -> (label: String, params: [String: Any]) {
let reflection = Mirror(reflecting: value)
guard reflection.displayStyle == .enum,
let associated = reflection.children.first else {
return ("\(value)", [:])

if reflection.displayStyle == .dictionary, let dictionary = value as? [String: Any] {
return ("\(value)", dictionary)
}
let values = Mirror(reflecting: associated.value).children
var valuesArray = [String: Any]()
if values.count > 0 {
for case let item in values where item.label != nil {
valuesArray[item.label!] = item.value

if reflection.displayStyle == .enum, let associated = reflection.children.first {
let values = Mirror(reflecting: associated.value).children
var valuesArray = [String: Any]()
if values.count > 0 {
for case let item in values where item.label != nil {
valuesArray[item.label!] = item.value
}
return (associated.label!, valuesArray)
} else {
valuesArray[associated.label!] = associated.value
return (associated.label!, valuesArray)
}
return (associated.label!, valuesArray)
} else {
valuesArray[associated.label!] = associated.value
return (associated.label!, valuesArray)
return ("\(value)", [:])
}
}

Expand Down

0 comments on commit f467c6a

Please sign in to comment.