File: package_range.ex

package info (click to toggle)
erlang-hex 2.0.6-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,204 kB
  • sloc: erlang: 2,950; sh: 203; makefile: 10
file content (36 lines) | stat: -rw-r--r-- 1,146 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# Vendored from hex_solver v0.2.2 (2634e31), do not edit manually

defmodule Hex.Solver.PackageRange do
  @moduledoc false

  alias Hex.Solver.PackageRange
  alias Hex.Solver.Constraints.Range

  defstruct repo: nil,
            name: nil,
            constraint: nil

  def to_string(%PackageRange{name: "$root"}), do: "your app"
  def to_string(%PackageRange{name: "$lock"}), do: "the lock"

  def to_string(%PackageRange{repo: nil, name: name, constraint: constraint}),
    do: "#{name}#{constraint(constraint)}"

  def to_string(%PackageRange{repo: repo, name: name, constraint: constraint}),
    do: "#{repo}/#{name}#{constraint(constraint)}"

  defp constraint(%Range{min: nil, max: nil}), do: ""
  defp constraint(constraint), do: " #{constraint}"

  defimpl String.Chars do
    defdelegate to_string(package_range), to: Hex.Solver.PackageRange
  end

  defimpl Inspect do
    def inspect(%{repo: nil, name: name, constraint: constraint}, _opts),
      do: "#PackageRange<#{name} #{constraint}>"

    def inspect(%{repo: repo, name: name, constraint: constraint}, _opts),
      do: "#PackageRange<#{repo}/#{name} #{constraint}>"
  end
end