Skip to content

Commit

Permalink
Add support for passing a function to validate application's version
Browse files Browse the repository at this point in the history
  • Loading branch information
yrashk committed Oct 14, 2012
1 parent 2f4b815 commit 30e681c
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions lib/app.ex
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@ defrecord Relex.App, name: nil, version: nil, path: nil, app: nil, type: :perman

defp version_matches?(nil, _app), do: true
defp version_matches?(version, app) do
if is_record(version, Regex) do
cond do
is_record(version, Regex) ->
Regex.match?(version, version(app))
else
is_function(version, 1) ->
version.(app)
true ->
to_binary(version(app)) == to_binary(version)
end
end
Expand All @@ -81,7 +84,14 @@ end

defimpl Binary.Inspect, for: Relex.App do
def inspect(Relex.App[name: name, version: version], _opts) do
if is_record(version, Regex), do: version = inspect(version)
cond do
is_record(version, Regex) ->
version = inspect(version)
is_function(version) ->
version = "<version checked by #{inspect(version)}>"
true ->
:ok
end
version = if nil?(version), do: "", else: "-#{version}"
"#{name}#{version}"
end
Expand Down

0 comments on commit 30e681c

Please sign in to comment.