Skip to content

Commit

Permalink
fix: Recursion happening Role.init?(rawValue: String) and Role.init(k…
Browse files Browse the repository at this point in the history
…nownRole: KnownRole)
  • Loading branch information
devahmedshendy committed Sep 24, 2023
1 parent 406009c commit f4b52a2
Showing 1 changed file with 31 additions and 24 deletions.
55 changes: 31 additions & 24 deletions Sources/SyndiKit/Formats/Media/Podcast/PodcastPerson+Role.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,36 @@ extension PodcastPerson {

init?(role: Role) {
switch role {
case .guest: self = .guest
case .host: self = .host
case .editor: self = .editor
case .writer: self = .writer
case .designer: self = .designer
case .composer: self = .composer
case .producer: self = .producer
case .unknown: return nil

case .guest: self = .guest
case .host: self = .host
case .editor: self = .editor
case .writer: self = .writer
case .designer: self = .designer
case .composer: self = .composer
case .producer: self = .producer
case .unknown: return nil
}
}
}

public enum Role: Codable, Equatable, RawRepresentable {
case guest
case host
case editor
case writer
case designer
case composer
case producer
case unknown(String)

public var rawValue: String {
if let knownRole = KnownRole(role: self) {
return knownRole.rawValue
} else if case let .unknown(string) = self {
return string
} else {
fatalError()
fatalError("This should never happen!")

Check warning on line 55 in Sources/SyndiKit/Formats/Media/Podcast/PodcastPerson+Role.swift

View check run for this annotation

Codecov / codecov/patch

Sources/SyndiKit/Formats/Media/Podcast/PodcastPerson+Role.swift#L53-L55

Added lines #L53 - L55 were not covered by tests
}
}

Expand All @@ -55,26 +64,24 @@ extension PodcastPerson {
}
}

private init(knownRole : KnownRole) {
self.init(rawValue: knownRole.rawValue)!
}

public init?(rawValue: String) {
if let knownRole = KnownRole(rawValue: rawValue) {
self = .init(knownRole: knownRole)
} else {
self = .unknown(rawValue)

Check warning on line 71 in Sources/SyndiKit/Formats/Media/Podcast/PodcastPerson+Role.swift

View check run for this annotation

Codecov / codecov/patch

Sources/SyndiKit/Formats/Media/Podcast/PodcastPerson+Role.swift#L67-L71

Added lines #L67 - L71 were not covered by tests
}
}


case guest
case host
case editor
case writer
case designer
case composer
case producer
case unknown(String)

private init(knownRole: KnownRole) {
switch knownRole {
case .guest: self = .guest
case .host: self = .host
case .editor: self = .editor
case .writer: self = .writer
case .designer: self = .designer
case .composer: self = .composer
case .producer: self = .producer
}
}
}
}

0 comments on commit f4b52a2

Please sign in to comment.