Skip to content

Commit 4321688

Browse files
committed
Massive cleanup, deprecated most of the class methods
1 parent 6dbca33 commit 4321688

File tree

3 files changed

+608
-511
lines changed

3 files changed

+608
-511
lines changed

JLRoutes/JLRoutes.h

Lines changed: 78 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/*
22
Copyright (c) 2016, Joel Levin
33
All rights reserved.
4-
4+
55
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6-
6+
77
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
88
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
99
Neither the name of JLRoutes nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
@@ -19,80 +19,116 @@ FOUNDATION_EXTERN NSString *const kJLRoutePatternKey;
1919
FOUNDATION_EXTERN NSString *const kJLRouteURLKey;
2020
FOUNDATION_EXTERN NSString *const kJLRouteNamespaceKey;
2121
FOUNDATION_EXTERN NSString *const kJLRouteWildcardComponentsKey;
22+
2223
FOUNDATION_EXTERN NSString *const kJLRoutesGlobalNamespaceKey;
2324

2425

2526
@interface JLRoutes : NSObject
26-
/** @class JLRoutes
27-
JLRoutes is a way to manage URL routes and invoke them from a URL.
28-
*/
2927

30-
/// Returns the global routing namespace (this is used by the +addRoute methods by default)
28+
/// Controls whether or not this router will try to match a URL with global routes if it can't be matched in the current namespace. Default is NO.
29+
@property (nonatomic, assign) BOOL shouldFallbackToGlobalRoutes;
30+
31+
/// Called any time routeURL returns NO. Respects shouldFallbackToGlobalRoutes.
32+
@property (nonatomic, copy) void (^__nullable unmatchedURLHandler)(JLRoutes *routes, NSURL *__nullable URL, NSDictionary<NSString *, id> *__nullable parameters);
33+
34+
35+
#pragma mark - Routing Schemes
36+
37+
/// Returns the global routing scheme (this is used by the +addRoute methods by default)
3138
+ (instancetype)globalRoutes;
3239

3340
/// Returns a routing namespace for the given scheme
3441
+ (instancetype)routesForScheme:(NSString *)scheme;
3542

36-
/// Tells JLRoutes that it should manually replace '+' in parsed values to ' '. Defaults to YES.
37-
+ (void)setShouldDecodePlusSymbols:(BOOL)shouldDecode;
38-
+ (BOOL)shouldDecodePlusSymbols;
43+
/// Unregister and delete an entire scheme namespace
44+
+ (void)unregisterRouteScheme:(NSString *)scheme;
45+
46+
/// Unregister all routes
47+
+ (void)unregisterAllRouteSchemes;
48+
49+
50+
#pragma mark - Registering Routes
3951

4052
/// Registers a routePattern with default priority (0) in the receiving scheme namespace.
41-
+ (void)addRoute:(NSString *)routePattern handler:(BOOL (^__nullable)(NSDictionary<NSString *, id> *parameters))handlerBlock;
42-
- (void)addRoute:(NSString *)routePattern handler:(BOOL (^__nullable)(NSDictionary<NSString *, id> *parameters))handlerBlock; // instance method
53+
- (void)addRoute:(NSString *)routePattern handler:(BOOL (^__nullable)(NSDictionary<NSString *, id> *parameters))handlerBlock;
4354

44-
/// Registers multiple routePatterns for one handler with default priority (0) in the receiving scheme namespace.
45-
+ (void)addRoutes:(NSArray<NSString *> *)routePatterns handler:(BOOL (^__nullable)(NSDictionary<NSString *, id> *parameters))handlerBlock;
46-
- (void)addRoutes:(NSArray<NSString *> *)routePatterns handler:(BOOL (^__nullable)(NSDictionary<NSString *, id> *parameters))handlerBlock; // instance method
55+
/// Registers a routePattern in the global scheme namespace with a handlerBlock to call when the route pattern is matched by a URL.
56+
/// The block returns a BOOL representing if the handlerBlock actually handled the route or not. If
57+
/// a block returns NO, JLRoutes will continue trying to find a matching route.
58+
- (void)addRoute:(NSString *)routePattern priority:(NSUInteger)priority handler:(BOOL (^__nullable)(NSDictionary<NSString *, id> *parameters))handlerBlock;
4759

60+
/// Registers multiple routePatterns for one handler with default priority (0) in the receiving scheme namespace.
61+
- (void)addRoutes:(NSArray<NSString *> *)routePatterns handler:(BOOL (^__nullable)(NSDictionary<NSString *, id> *parameters))handlerBlock;
4862

4963
/// Removes a routePattern from the receiving scheme namespace.
50-
+ (void)removeRoute:(NSString *)routePattern;
51-
- (void)removeRoute:(NSString *)routePattern; // instance method
64+
- (void)removeRoute:(NSString *)routePattern;
5265

5366
/// Removes all routes from the receiving scheme namespace.
54-
+ (void)removeAllRoutes;
55-
- (void)removeAllRoutes; // instance method
56-
57-
/// Unregister and delete an entire scheme namespace
58-
+ (void)unregisterRouteScheme:(NSString *)scheme;
67+
- (void)removeAllRoutes;
5968

6069
/// Registers a routePattern with default priority (0) using dictionary-style subscripting.
6170
- (void)setObject:(nullable id)handlerBlock forKeyedSubscript:(NSString *)routePatten;
6271

63-
/// Registers a routePattern in the global scheme namespace with a handlerBlock to call when the route pattern is matched by a URL.
64-
/// The block returns a BOOL representing if the handlerBlock actually handled the route or not. If
65-
/// a block returns NO, JLRoutes will continue trying to find a matching route.
66-
+ (void)addRoute:(NSString *)routePattern priority:(NSUInteger)priority handler:(BOOL (^__nullable)(NSDictionary<NSString *, id> *parameters))handlerBlock;
67-
- (void)addRoute:(NSString *)routePattern priority:(NSUInteger)priority handler:(BOOL (^__nullable)(NSDictionary<NSString *, id> *parameters))handlerBlock; // instance method
6872

69-
/// Routes a URL, calling handler blocks (for patterns that match URL) until one returns YES, optionally specifying add'l parameters
73+
#pragma mark - Routing URLs
74+
75+
/// Returns whether a route will match a given URL in any routes scheme, but does not call any blocks.
76+
+ (BOOL)canRouteURL:(nullable NSURL *)URL;
77+
78+
/// Returns whether a route will match a given URL in a specific scheme, but does not call any blocks.
79+
- (BOOL)canRouteURL:(nullable NSURL *)URL;
80+
81+
/// Routes a URL in any routes scheme, calling handler blocks for patterns that match the URL until one returns YES.
82+
/// If no matching route is found, the unmatchedURLHandler will be called (if set).
7083
+ (BOOL)routeURL:(nullable NSURL *)URL;
84+
85+
/// Routes a URL in a specific scheme, calling handler blocks for patterns that match the URL until one returns YES.
86+
/// If no matching route is found, the unmatchedURLHandler will be called (if set).
87+
- (BOOL)routeURL:(nullable NSURL *)URL;
88+
89+
/// Routes a URL in any routes scheme, calling handler blocks (for patterns that match URL) until one returns YES.
90+
/// Additional parameters get passed through to the matched route block.
7191
+ (BOOL)routeURL:(nullable NSURL *)URL withParameters:(nullable NSDictionary<NSString *, id> *)parameters;
7292

73-
- (BOOL)routeURL:(nullable NSURL *)URL; // instance method
74-
- (BOOL)routeURL:(nullable NSURL *)URL withParameters:(nullable NSDictionary<NSString *, id> *)parameters; // instance method
93+
/// Routes a URL in a specific scheme, calling handler blocks (for patterns that match URL) until one returns YES.
94+
/// Additional parameters get passed through to the matched route block.
95+
- (BOOL)routeURL:(nullable NSURL *)URL withParameters:(nullable NSDictionary<NSString *, id> *)parameters;
96+
97+
@end
7598

76-
/// Returns whether a route exists for a URL
77-
+ (BOOL)canRouteURL:(nullable NSURL *)URL;
78-
+ (BOOL)canRouteURL:(nullable NSURL *)URL withParameters:(nullable NSDictionary<NSString *, id> *)parameters;
7999

80-
- (BOOL)canRouteURL:(nullable NSURL *)URL; // instance method
81-
- (BOOL)canRouteURL:(nullable NSURL *)URL withParameters:(nullable NSDictionary<NSString *, id> *)parameters; // instance method
100+
#pragma mark - Global Options
82101

83-
/// Prints the entire routing table
84-
+ (NSString *)description;
102+
@interface JLRoutes (GlobalOptions)
85103

86-
/// Allows configuration of verbose logging. Default is NO. This is mostly just helpful with debugging.
104+
/// Enable or disable verbose logging. Defaults to NO.
87105
+ (void)setVerboseLoggingEnabled:(BOOL)loggingEnabled;
88-
+ (BOOL)isVerboseLoggingEnabled;
89106

90-
/// Controls whether or not this routes controller will try to match a URL with global routes if it can't be matched in the current namespace. Default is NO.
91-
@property (nonatomic, assign) BOOL shouldFallbackToGlobalRoutes;
107+
/// Tells JLRoutes that it should manually replace '+' in parsed values to ' '. Defaults to YES.
108+
+ (void)setShouldDecodePlusSymbols:(BOOL)shouldDecode;
92109

93-
/// Called any time routeURL returns NO. Respects shouldFallbackToGlobalRoutes.
94-
@property (nonatomic, copy) void (^__nullable unmatchedURLHandler)(JLRoutes *routes, NSURL *__nullable URL, NSDictionary<NSString *, id> *__nullable parameters);
110+
@end
111+
112+
113+
#pragma mark - Deprecated
114+
115+
@interface JLRoutes (Deprecated)
116+
117+
// All the class method conveniences have been deprecated. They make the API/header confusing and are unncessary.
118+
// If you're using these, please switch to calling the matching instance method on +globalRoutes instead for the same behavior.
119+
120+
+ (void)addRoute:(NSString *)routePattern handler:(BOOL (^__nullable)(NSDictionary<NSString *, id> *parameters))handlerBlock DEPRECATED_MSG_ATTRIBUTE("Use the matching instance method on +globalRoutes instead.");
121+
+ (void)addRoute:(NSString *)routePattern priority:(NSUInteger)priority handler:(BOOL (^__nullable)(NSDictionary<NSString *, id> *parameters))handlerBlock DEPRECATED_MSG_ATTRIBUTE("Use the matching instance method on +globalRoutes instead.");
122+
+ (void)addRoutes:(NSArray<NSString *> *)routePatterns handler:(BOOL (^__nullable)(NSDictionary<NSString *, id> *parameters))handlerBlock DEPRECATED_MSG_ATTRIBUTE("Use the matching instance method on +globalRoutes instead.");
123+
+ (void)removeRoute:(NSString *)routePattern DEPRECATED_MSG_ATTRIBUTE("Use the matching instance method on +globalRoutes instead.");
124+
+ (void)removeAllRoutes DEPRECATED_MSG_ATTRIBUTE("Use the matching instance method on +globalRoutes instead.");
125+
+ (BOOL)canRouteURL:(nullable NSURL *)URL withParameters:(nullable NSDictionary<NSString *, id> *)parameters DEPRECATED_MSG_ATTRIBUTE("Use +canRouteURL: instead.");
126+
127+
// Other deprecations
128+
129+
- (BOOL)canRouteURL:(nullable NSURL *)URL withParameters:(nullable NSDictionary<NSString *, id> *)parameters DEPRECATED_MSG_ATTRIBUTE("Use -canRouteURL: instead.");
95130

96131
@end
97132

133+
98134
NS_ASSUME_NONNULL_END

0 commit comments

Comments
 (0)