-
Notifications
You must be signed in to change notification settings - Fork 376
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
Move signature logic to its own module #195
Conversation
Removed secure_compare specs as it is not part of the public API anymore. HMAC specs should already cover the functionality of secure_compare.
Thank you very much! This is exactly the way to go. 👍 |
|
||
module JWT | ||
module Signature | ||
extend self |
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.
Please use module_function
instead of extend self
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.
what about private
functions? I don't think it's possible to define private function with module_functions
.
What are the benefits of module_functions
?
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.
Using module_function
is the preferred coding style.
You're alway able to define a function as private by using this syntax:
def my_fun(my_param) do
puts my_param
end
private :my_fun
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 don't think module_function
respects the private visibility.
module A
module_function
def my_fun(my_param)
puts my_param
end
private :my_fun
end
A.my_fun("calling private method") #=> "calling private method"
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.
Please merge the current master into your branch. There have been changes. The small issues are commented inline.
Thanks for the comments @excpt This branch is already up-to-date with master, sorry I missed In my opinion the constants Do you still think it's worth moving the constants to |
Agreed. Move the algorithms into the signature module. This makes way more sense. The rest is looking fine. After that change i'll merge your PR. Thanks again. 🍻 |
After looking through the last refactoring to move logic out of the jwt.rb monolith I think the better solution to that problem is to rewrite the module as a class. The Encoding and Verify refactorings took the same approach. This will give you full control about what's private logic and what should be exposed to the outside. |
I think normally a class is meant to have both behavior and state. In this case, So, if you implement And I think @excpt do you still prefer to implement this as a class? would you use instance or class methods? |
I totally over-engineered the problem. Sorry. Thank you very much for the contribution and your patience to withstand my pretty silly review. 👍 The code solves the problem and this is what counts. |
@EmilioCristalli |
Not sure if this change was planned, but seemed aligned with the rest of modules the gem has.
Also I think this will help to start working on redefining the public API (I guess that is planned for version 2).
Let me know what you think, if you want me to make changes, or if it's just not the direction you guys wanted to go.
Thanks!