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
version: add major, minor, patch methods #8183
version: add major, minor, patch methods #8183
Conversation
One thing I noticed is that
Whereas this works fine with
I might open another PR to address this |
Might be good to make this a module so it can be shared between both |
Can you provide an example of how it should be used?
Agreed with this, I'd really love to see this deduplicate some Cask code. |
Can a brew/Library/Homebrew/dev-cmd/audit.rb Lines 754 to 760 in c49ef80
|
It would turn the following incantation in the
into:
Not that much shorter, but somewhat more comprehensible to the Ruby-challenged like me. There are at least 5 other formulae I'm tracking that could use the same improvement. |
Yup, makes sense. Can this be stripped down to the minimum number of methods we definitely have a use for in formulae and/or Homebrew/brew (including cask)? |
Assuming stable_version_string = stable.version.to_s
stable_url_version = Version.parse(stable.url)
stable_url_minor_version = stable_url_version.minor.to_i
formula_suffix = stable.version.patch.to_i Also a few lines down we could replace |
I think all of these methods except maybe
I tried doing this but I don't think there's really any shared logic in how |
Let's skip this for now and otherwise can include them.
This would be a great project to attempt! A general good start should be seeing if you can use our version logic without changing the tests. |
For some reason, I thought that it was almost always the |
7b7a3fc
to
1520675
Compare
1520675
to
919e94b
Compare
Made a number of quality-of-life additions/changes, hopefully nothing will break |
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.
A few readability tweaks then 👍🏻 to 🚢 . Nice work @SeekingMeaning!
Library/Homebrew/version.rb
Outdated
@@ -469,6 +486,26 @@ def <=>(other) | |||
end | |||
alias eql? == | |||
|
|||
def major | |||
tokens[0] |
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.
tokens[0] | |
tokens.first |
Library/Homebrew/version.rb
Outdated
end | ||
|
||
def minor | ||
tokens[1] |
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.
tokens[1] | |
tokens.second |
Library/Homebrew/version.rb
Outdated
end | ||
|
||
def patch | ||
tokens[2] |
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.
tokens[2] | |
tokens.third |
Library/Homebrew/version.rb
Outdated
end | ||
|
||
def major_minor | ||
Version.new([major, minor].reject(&:nil?).join(".")) |
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.
Version.new([major, minor].reject(&:nil?).join(".")) | |
Version.new([major, minor].compact.join(".")) |
Library/Homebrew/version.rb
Outdated
end | ||
|
||
def major_minor_patch | ||
Version.new([major, minor, patch].reject(&:nil?).join(".")) |
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.
Version.new([major, minor, patch].reject(&:nil?).join(".")) | |
Version.new([major, minor, patch].compact.join(".")) |
brew style
with your changes locally?brew tests
with your changes locally?This adds five new methods to the
Version
class:major
,minor
,patch
,major_minor
,major_minor_patch
. In particular,Version#major
will be useful for determining the version suffix ofgcc
: Homebrew/homebrew-core#59485(Based on
cask/dsl/version
)Example usage
Examples in
brew irb
: