-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support bit mask on the RKRequestMethod method
param
#1476
Support bit mask on the RKRequestMethod method
param
#1476
Conversation
Yeah I have thought about this recently. Should definitely make the change -- should be able to do so transparently |
Allright, thanks for the fast answer that's comforting me on making a pull request (and keep it transparently of course) |
Oh! I'm facing some design issues... the fact is that if we store the bitmask method value in the So one solution would be to have a new class method on |
You should still be able to do an exact value comparison with a bitmask. On the request/response descriptors it would make sense to use them as a bit mask, but in routes and other situations they will need to be pinned to an exact value and raise an |
Totally agree, we can make exact value comparison of course.
Can't find where |
Ah it's actually not currently in use on the descriptors -- I have a branch where I had introduced it as a new option that is unmerged. Had forgotten |
Nice! I'm reassured, I was doubting of my searching skill ;) |
Just go ahead with your development and shoot a pull request over whenever you are ready. I'll take care of integration with any other branches |
Fine with me, I'll do that. Thanks for the hints |
Looks good -- the only other change I would make is to introduce |
Thanks! first, declare that at the end of the enum RKRequestMethodAny = (RKRequestMethodGET |
RKRequestMethodPOST |
RKRequestMethodPUT |
RKRequestMethodDELETE |
RKRequestMethodHEAD |
RKRequestMethodPATCH |
RKRequestMethodOPTIONS) or second method, less explicit RKRequestMethodAny = ~(0) got a preference ? |
Go with the more explicit option |
Well the advantage of the second one would be that it would automatically include any additional methods defined, though I feel like the explicit option is easy to read. |
Exactly, it would be more robust for future additions but harder to read, that's why I was asking for a preference. |
Sold. |
and clean up declarations of RKRequestMethodAny in other classes
|
||
- (void)testThatYesIsReturnedWhenTheGivenRequestMethodIsAny | ||
{ | ||
expect(RKIsAnExactRequestMethodMatch(RKRequestMethodAny)).to.beTruthy(); |
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.
Shouldn't this return false?
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.
Humm no, what I meant by RKIsAnExactRequestMethodMatch
is that the given HTTP method passed to the function is equal to one and only one of the RKRequestMethod options.
The idea is to check if the method
is a power of two, or equals to RKRequestMethodAny.
Does that make sense ?
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.
But RKRequestMethodAny is a mask representing all request methods (so it's not exact)
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.
Right, that's why I've added this condition
We can rename the static function if that's unclear of course
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.
I guess that just doesn't jibe with my interpretation of the word exact
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.
I agree with @segiddins -- RKRequestMethodANY
should not be considered an exact method (nor should RKRequestMethodInvalid
. What I am looking for in the conditions is that the given value corresponds to exactly one valid HTTP request method.
Maybe a better name is RKAssertRequestMethodSpecifiesHTTPMethod()
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.
I can rename it RKIsMatchingASingleRequestMethodOption
if you want to ?
Sorry another revision: It is valid to use an the method as a bit mask for routing purposes with: + (instancetype)routeWithClass:(Class)objectClass pathPattern:(NSString *)pathPattern method:(RKRequestMethod)method;
+ (instancetype)routeWithRelationshipName:(NSString *)name objectClass:(Class)objectClass pathPattern:(NSString *)pathPattern method:(RKRequestMethod)method; This is because these methods are matched by HTTP method to URL, while named routes go from a name -> URL and method. If multiple routes are registered that overlap and the value of one is not |
and do not consider RKRequestMethodANY as an exact method
This will also make #1439 a lot easier to implement |
Did some additional cleanup and merged to development in c73ac51 |
Great! glad to here that |
some things we might have missed: |
Taking care of the |
…tRequestOperationsWithMethod:matchingPathPattern:` refs #1476
…tRequestOperationsWithMethod:matchingPathPattern:` refs RestKit#1476
Is there a reason why you didn't use a bitwise aware enum that could let us do things like :
Just to save us from duplicate lines ;)