-
Notifications
You must be signed in to change notification settings - Fork 280
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
Add pronto to pre_push hooks #706
Conversation
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.
Thanks for the pull request @povilasjurcys.
Overall looks good, but I'm not clear on the need for protected
.
@@ -10,7 +10,7 @@ class Base < Overcommit::Hook::Base | |||
|
|||
def_delegators :@context, :modified_lines_in_file, :amendment?, :initial_commit? | |||
|
|||
private | |||
protected |
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.
Can you explain why we're making this change when the previous private
worked?
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.
extract_messages
is used in child classes.
private" means that only methods of this class can access the member. "protected" means that methods of this class, or of derived classes, can access the member.
source: https://answers.unity.com/questions/610093/what-is-the-difference-between-private-and-protect.html
Just wanted to handle this in more "correct" way. Ruby does dot handle private
and protected
very well anyways, but I personally use protected
when I want to indicate that method might be overwritten in child class. Sadly, in practice you can do the same with private
methods too.
Let me know if you prefer private more.
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.
You are referencing documentation for a language that is not Ruby. protected
, in a nutshell, allows a method to be called by another instance of the same class or subclass. It is not necessary in this context.
From https://ruby-doc.org/core-2.5.3/Module.html#method-i-protected
If a method has protected visibility, it is callable only where
self
of the context is the same as the method. (method definition or instance_eval). This behavior is different from Java's protected method. Usuallyprivate
should be used.
Emphasis mine.
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.
thanks for pointing this out. You're right. private
it is
lib/overcommit/hook/pre_push/base.rb
Outdated
@@ -15,6 +16,12 @@ def run? | |||
(include_remote_ref_deletions? || !@context.remote_ref_deletion?) | |||
end | |||
|
|||
protected |
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.
Why are we using protected
? There isn't a situation where another instance is attempting to call this method, so private
is the correct level of access control. If I'm misunderstanding your intent, let me know.
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.
same answer as for https://github.com/sds/overcommit/pull/706/files#r386066591
Thanks! |
Currently it's possible to add pronto only as PreCommit hook. This PR allows to add pronto as PrePush hook too.