This repository has been archived by the owner on Sep 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 120
Reintroduce subscripting ifNull/ifNotFound methods (with deprecation warnings) #149
Merged
mdmathias
merged 4 commits into
mattmatt/ParsingOptions
from
jgallagher/deprecated-subscripting-options
Mar 24, 2016
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1c625a2
Reintroduce subscripting ifNull/ifNotFound methods (with deprecation …
hydhknn 85f12a9
Use "// MARK" for deprecated methods
hydhknn d9d7711
Add quotes around code snippets in deprecation messages
hydhknn d14681c
Remove tests of deprecated methods
hydhknn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -539,3 +539,105 @@ extension JSON { | |
} | ||
|
||
} | ||
|
||
// Deprecated methods. | ||
|
||
extension JSON { | ||
|
||
@available(*, deprecated, message="Use decode(_:alongPath:type:) with options [.MissingKeyBecomesNil]") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know it doesn't get formatted nicely, but do you think it's worth using backticks around the code in these messages? I suggest it because it may help readers of these messages to quickly identify the thing they need to do. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like built-in warnings use single quotes around code bits. Will change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
public func decode<Decoded: JSONDecodable>(path: JSONPathType..., ifNotFound: Swift.Bool, type: Decoded.Type = Decoded.self) throws -> Decoded? { | ||
let options: SubscriptingOptions = ifNotFound ? [.MissingKeyBecomesNil] : [] | ||
return try mapOptionalAtPath(path, alongPath: options, transform: Decoded.init) | ||
} | ||
|
||
@available(*, deprecated, message="Use decode(_:alongPath:type:) with options [.NullBecomesNil]") | ||
public func decode<Decoded: JSONDecodable>(path: JSONPathType..., ifNull: Swift.Bool, type: Decoded.Type = Decoded.self) throws -> Decoded? { | ||
let options: SubscriptingOptions = ifNull ? [.NullBecomesNil] : [] | ||
return try mapOptionalAtPath(path, alongPath: options, transform: Decoded.init) | ||
} | ||
|
||
@available(*, deprecated, message="Use double(_:alongPath:) with options [.MissingKeyBecomesNil]") | ||
public func double(path: JSONPathType..., ifNotFound: Swift.Bool) throws -> Swift.Double? { | ||
let options: SubscriptingOptions = ifNotFound ? [.MissingKeyBecomesNil] : [] | ||
return try mapOptionalAtPath(path, alongPath: options, transform: Swift.Double.init) | ||
} | ||
|
||
@available(*, deprecated, message="Use double(_:alongPath:) with options [.NullBecomesNil]") | ||
public func double(path: JSONPathType..., ifNull: Swift.Bool) throws -> Swift.Double? { | ||
let options: SubscriptingOptions = ifNull ? [.NullBecomesNil] : [] | ||
return try mapOptionalAtPath(path, alongPath: options, transform: Swift.Double.init) | ||
} | ||
|
||
@available(*, deprecated, message="Use int(_:alongPath:) with options [.MissingKeyBecomesNil]") | ||
public func int(path: JSONPathType..., ifNotFound: Swift.Bool) throws -> Swift.Int? { | ||
let options: SubscriptingOptions = ifNotFound ? [.MissingKeyBecomesNil] : [] | ||
return try mapOptionalAtPath(path, alongPath: options, transform: Swift.Int.init) | ||
} | ||
|
||
@available(*, deprecated, message="Use int(_:alongPath:) with options [.NullBecomesNil]") | ||
public func int(path: JSONPathType..., ifNull: Swift.Bool) throws -> Swift.Int? { | ||
let options: SubscriptingOptions = ifNull ? [.NullBecomesNil] : [] | ||
return try mapOptionalAtPath(path, alongPath: options, transform: Swift.Int.init) | ||
} | ||
|
||
@available(*, deprecated, message="Use string(_:alongPath:) with options [.MissingKeyBecomesNil]") | ||
public func string(path: JSONPathType..., ifNotFound: Swift.Bool) throws -> Swift.String? { | ||
let options: SubscriptingOptions = ifNotFound ? [.MissingKeyBecomesNil] : [] | ||
return try mapOptionalAtPath(path, alongPath: options, transform: Swift.String.init) | ||
} | ||
|
||
@available(*, deprecated, message="Use string(_:alongPath:) with options [.NullBecomesNil]") | ||
public func string(path: JSONPathType..., ifNull: Swift.Bool) throws -> Swift.String? { | ||
let options: SubscriptingOptions = ifNull ? [.NullBecomesNil] : [] | ||
return try mapOptionalAtPath(path, alongPath: options, transform: Swift.String.init) | ||
} | ||
|
||
@available(*, deprecated, message="Use bool(_:alongPath:) with options [.MissingKeyBecomesNil]") | ||
public func bool(path: JSONPathType..., ifNotFound: Swift.Bool) throws -> Swift.Bool? { | ||
let options: SubscriptingOptions = ifNotFound ? [.MissingKeyBecomesNil] : [] | ||
return try mapOptionalAtPath(path, alongPath: options, transform: Swift.Bool.init) | ||
} | ||
|
||
@available(*, deprecated, message="Use bool(_:alongPath:) with options [.NullBecomesNil]") | ||
public func bool(path: JSONPathType..., ifNull: Swift.Bool) throws -> Swift.Bool? { | ||
let options: SubscriptingOptions = ifNull ? [.NullBecomesNil] : [] | ||
return try mapOptionalAtPath(path, alongPath: options, transform: Swift.Bool.init) | ||
} | ||
|
||
@available(*, deprecated, message="Use array(_:alongPath:) with options [.MissingKeyBecomesNil]") | ||
public func array(path: JSONPathType..., ifNotFound: Swift.Bool) throws -> [JSON]? { | ||
let options: SubscriptingOptions = ifNotFound ? [.MissingKeyBecomesNil] : [] | ||
return try mapOptionalAtPath(path, alongPath: options, transform: JSON.getArray) | ||
} | ||
|
||
@available(*, deprecated, message="Use array(_:alongPath:) with options [.NullBecomesNil]") | ||
public func array(path: JSONPathType..., ifNull: Swift.Bool) throws -> [JSON]? { | ||
let options: SubscriptingOptions = ifNull ? [.NullBecomesNil] : [] | ||
return try mapOptionalAtPath(path, alongPath: options, transform: JSON.getArray) | ||
} | ||
|
||
@available(*, deprecated, message="Use arrayOf(_:alongPath:) with options [.MissingKeyBecomesNil]") | ||
public func arrayOf<Decoded: JSONDecodable>(path: JSONPathType..., ifNotFound: Swift.Bool) throws -> [Decoded]? { | ||
let options: SubscriptingOptions = ifNotFound ? [.MissingKeyBecomesNil] : [] | ||
return try mapOptionalAtPath(path, alongPath: options, transform: JSON.getArrayOf) | ||
} | ||
|
||
@available(*, deprecated, message="Use arrayOf(_:alongPath:) with options [.NullBecomesNil]") | ||
public func arrayOf<Decoded: JSONDecodable>(path: JSONPathType..., ifNull: Swift.Bool) throws -> [Decoded]? { | ||
let options: SubscriptingOptions = ifNull ? [.NullBecomesNil] : [] | ||
return try mapOptionalAtPath(path, alongPath: options, transform: JSON.getArrayOf) | ||
} | ||
|
||
@available(*, deprecated, message="Use dictionary(_:alongPath:) with options [.MissingKeyBecomesNil]") | ||
public func dictionary(path: JSONPathType..., ifNotFound: Swift.Bool) throws -> [Swift.String: JSON]? { | ||
let options: SubscriptingOptions = ifNotFound ? [.MissingKeyBecomesNil] : [] | ||
return try mapOptionalAtPath(path, alongPath: options, transform: JSON.getDictionary) | ||
} | ||
|
||
@available(*, deprecated, message="Use dictionary(_:alongPath:) with options [.NullBecomesNil]") | ||
public func dictionary(path: JSONPathType..., ifNull: Swift.Bool) throws -> [Swift.String: JSON]? { | ||
let options: SubscriptingOptions = ifNull ? [.NullBecomesNil] : [] | ||
return try mapOptionalAtPath(path, alongPath: options, transform: JSON.getDictionary) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have feels about
// MARK: - Deprecated methods
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I feel it should be that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha. 👍