Skip to content

Commit

Permalink
Add RawIntNotSupported
Browse files Browse the repository at this point in the history
  • Loading branch information
dreymonde committed Mar 28, 2016
1 parent 888809c commit b0af2b7
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Sources/Mapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public final class Mapper {
public enum Error: ErrorType {
case CantInitFromRawValue
case NoInterchangeData(key: String)
case RawIntNotSupported
}

public init(interchangeData: InterchangeData) {
Expand Down Expand Up @@ -44,6 +45,9 @@ extension Mapper {
}

public func from<T: RawRepresentable>(key: String) throws -> T {
guard T.self != Int.self else {
throw Error.RawIntNotSupported
}
let rawValue: T.RawValue = try interchangeData.get(key)
if let value = T(rawValue: rawValue) {
return value
Expand Down Expand Up @@ -90,6 +94,9 @@ extension Mapper {
}

public func fromArray<T: RawRepresentable>(key: String) throws -> [T] {
guard T.self != Int.self else {
throw Error.RawIntNotSupported
}
let inter: [InterchangeData] = try interchangeData.get(key)
return inter.flatMap {
do {
Expand Down Expand Up @@ -129,6 +136,9 @@ extension Mapper {
}

public func optionalFrom<T: RawRepresentable>(key: String) -> T? {
guard T.self != Int.self else {
return nil
}
do {
let rawValue: T.RawValue = try interchangeData.get(key)
if let value = T(rawValue: rawValue) {
Expand Down Expand Up @@ -183,6 +193,9 @@ extension Mapper {
}

public func optionalFromArray<T: RawRepresentable>(key: String) -> [T]? {
guard T.self != Int.self else {
return nil
}
do {
let inter: [InterchangeData] = try interchangeData.get(key)
return inter.flatMap {
Expand Down

0 comments on commit b0af2b7

Please sign in to comment.