eksperimental
Version requirement to match X and version above, including prereleases
Hi eveyone,
I am looking to match all versions above 1.11 including 1.11.0-rc0, any idea how to achieve this?
iex(35)> Version.match?("1.11.0-rc1", "~> 1.11")
false
iex(36)> Version.match?("1.11.0-rc1", "~> 1.11", allow_pre: true)
false
iex(37)> Version.match?("1.11.0-rc1", ">= 1.11", allow_pre: true)
** (Version.InvalidRequirementError) invalid requirement: ">= 1.11"
(elixir 1.13.0-rc.1) lib/version.ex:433: Version.parse_requirement!/1
(elixir 1.13.0-rc.1) lib/version.ex:278: Version.match?/3
iex(37)> Version.match?("1.11.0-rc1", ">= 1.11.0", allow_pre: true)
false
iex(38)> Version.match?("1.11.0-rc1", ">= 1.11-0")
** (Version.InvalidRequirementError) invalid requirement: ">= 1.11-0"
(elixir 1.13.0-rc.1) lib/version.ex:433: Version.parse_requirement!/1
(elixir 1.13.0-rc.1) lib/version.ex:278: Version.match?/3
The only way to achieve this, is by using the lowest prerelease that I could come up with -0 which is a bit hackish but gets the job done.
iex(38)> Version.match?("1.11.0-rc1", ">= 1.11.0-0")
true
iex(39)> Version.match?("1.12.0", ">= 1.11.0-0")
true
iex(41)> Version.match?("1.11.0-rc1", "~> 1.11-0")
true
iex(41)> Version.match?("1.12.0", "~> 1.11-0")
true
Is there anything that I am missing?
Most Liked
dimitarvp
FWIW, I couldn’t make your examples work with Rust either – tried it as a sort of a sanity double-check.
use semver::*;
fn main() {
let req_a = VersionReq::parse(">=1.11.0-rc").unwrap();
let v0 = Version::parse("1.11.0-rc0").unwrap();
let v1 = Version::parse("1.11.0-rc1").unwrap();
println!("Does {} match {} ? => {}", v0, req_a, req_a.matches(&v0));
println!("Does {} match {} ? => {}", v1, req_a, req_a.matches(&v1));
}
That was the only way I could make it return true. All other variants – namely 1.11.0 and 1.11 – yielded false. (And their library doesn’t accept the ~> ... format)
1
kip
ex_cldr Core Team
I typically do it this way:
iex> Version.match?("1.11.0-rc1", "~> 1.11 or ~> 1.11-rc")
true
1
kip
ex_cldr Core Team
iex> Version.match?("1.11.0", "~> 1.11-rc")
true
You are right!!! Wonder why I didn’t notice that before.
1
Popular in Questions
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]
15:22:35.803 [error] gen_event {lager_file_backend...
New
In Ruby, I can go:
User.find_by(email: "foobar@email.com").update(email: "hello@email.com")
How can I do something similar in Elixir? ...
New
What is the idiomatic way of matching for not nil in Elixir?
E.g.,
First way:
defp halt_if_not_signed_in(conn, signed_in_account) when...
New
Good day to you all.
I have been struggling to get a query involving like and ilike to work.
Can anyone assist me on this, please?
pro...
New
Hi all,
Trying to get some more clarity over utc_datetime and naive_datetime for Ecto:
https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
The Elixir Typespec docs show the following syntax for keyword lists in typespecs:
# ...
| [key: type] # keyword lis...
New
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
Hi guys, i’m new in the Elixir world, and i have to say, that i love it!
i’m having some problem to understand anonymous functions with ...
New
Given a string, how can I get access to its character by index? Enum.at("my_string", 2) doesn't work.
Or rather, not char, but a substr...
New
Other popular topics
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this:
...
New
I couldn’t find any guides that worked well with Phoenix 1.6.0 and esbuild. I hope this helps people test the waters and eases you into t...
New
I have an umbrella app.
Some of the apps inside depend on other apps in the umbrella, unsurprisingly.
I'm writing a test for one of t...
New
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
Hi all,
I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage.
I'm trying to use Postg...
New
Hi,
I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
Hey :wave:t3: Elixir community,
I’ve been learning Elixir, and working on some side projects. My editor of choice is VSCode, and althoug...
New








