Skip to content

Commit

Permalink
Add support for symbolic (named) versions
Browse files Browse the repository at this point in the history
Closes #10
  • Loading branch information
yrashk committed Sep 29, 2012
1 parent 6ef6af1 commit 5005f30
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
12 changes: 12 additions & 0 deletions lib/package.ex
Expand Up @@ -83,7 +83,19 @@ defrecord Expm.Package,
Expm.Repository.put repo, package
end

def fetch(repo, package) do
case Enum.reverse(List.sort(versions repo, package)) do
[] -> :not_found
[top|_] -> fetch(repo, package, top)
end
end

def fetch(repo, package, version) do
if is_binary(version) and
Regex.match?(%r/^[a-z]+.*/i,version) do # symbolic name
version = binary_to_atom(version) ## FIXME?
end

Expm.Repository.get repo, package, version
end

Expand Down
9 changes: 3 additions & 6 deletions lib/server.ex
Expand Up @@ -112,19 +112,16 @@ defmodule Expm.Server.Http do

def to_html(req, State[endpoint: :package, repository: repository] = state) do
{package, req} = Req.binding(:package, req)
case Enum.reverse(List.sort(Expm.Repository.versions repository, package)) do
[] -> pkg = "ERROR: No such package"
[version|_] ->
pkg = Expm.Repository.get repository, package, version
end
pkg = Expm.Package.fetch repository, package
if pkg == :not_found, do: pkg = "ERROR: No such package"
out = render_page(Expm.Server.Templates.package(pkg, repository), req, state)
{out, req, state}
end

def to_html(req, State[endpoint: :package_version, repository: repository] = state) do
{package, req} = Req.binding(:package, req)
{version, req} = Req.binding(:version, req)
pkg = Expm.Repository.get repository, package, version
pkg = Expm.Package.fetch repository, package, version
if pkg == :not_found, do: pkg = "ERROR: No such package"
out = render_page(Expm.Server.Templates.package(pkg, repository), req, state)
{out, req, state}
Expand Down
4 changes: 4 additions & 0 deletions package.head.exs
@@ -0,0 +1,4 @@
Expm.Package.new(name: "expm", description: "Elixir package manager",
version: :head, keywords: ["Elixir","Erlang","package","library","dependency","dependencies"],
maintainers: [[name: "Yurii Rashkovskii", email: "yrashk@gmail.com"]],
repositories: [[github: "yrashk/expm"]])

0 comments on commit 5005f30

Please sign in to comment.