Skip to content

Commit

Permalink
Fix Elixir 1.2+ deprecation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
DevL committed Jan 22, 2016
1 parent a264849 commit 47ec200
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Macros expanding into code that can be safely used in guard clauses.
Update your `mix.exs` file and run `mix deps.get`.
```elixir
defp deps do
[{:guardsafe, "~> 0.4.0"}]
[{:guardsafe, "~> 0.5.0"}]
end
```

Expand Down
26 changes: 13 additions & 13 deletions lib/guardsafe.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Guardsafe do
@vsn "0.4.0"
@vsn "0.5.0"
@doc false
def version, do: @vsn

Expand All @@ -20,7 +20,7 @@ defmodule Guardsafe do
"That's not odd."
end
def magic(number) when number |> divisible_by? 5 do
def magic(number) when number |> divisible_by?(5) do
"High five!"
end
end
Expand All @@ -33,7 +33,7 @@ defmodule Guardsafe do
## Examples
iex> 25 |> divisible_by? 5
iex> 25 |> divisible_by?(5)
true
"""
defmacro divisible_by?(number, divisor) do
Expand Down Expand Up @@ -77,7 +77,7 @@ defmodule Guardsafe do
generate_predicates = fn({module, types}) ->
@module String.to_atom "Elixir.#{module}"
types
|> Enum.each fn(type) ->
|> Enum.each(fn(type) ->
@predicate String.to_atom("#{type}?")
@function String.to_atom("is_#{type}")

Expand All @@ -95,15 +95,15 @@ defmodule Guardsafe do
unquote(@module).unquote(@function)(unquote(term))
end
end
end
end)
end

@doc """
Returns true if the term is between the low and high values, inclusively.
## Examples
iex> 5 |> within? 2, 10
iex> 5 |> within?(2, 10)
true
"""
defmacro within?(term, low, high) do
Expand All @@ -120,7 +120,7 @@ defmodule Guardsafe do
## Examples
iex> 5 |> date? {2015, 3, 20}
iex> 5 |> date?({2015, 3, 20})
true
"""
defmacro date?(term) do
Expand All @@ -129,9 +129,9 @@ defmodule Guardsafe do
and (tuple_size(unquote(term)) == 3)
and is_integer(elem(unquote(term), 0))
and is_integer(elem(unquote(term), 1))
and (elem(unquote(term), 1) |> within? 1, 12)
and (elem(unquote(term), 1) |> within?(1, 12))
and is_integer(elem(unquote(term), 2))
and (elem(unquote(term), 2) |> within? 1, 31)
and (elem(unquote(term), 2) |> within?(1, 31))
end
end

Expand All @@ -143,19 +143,19 @@ defmodule Guardsafe do
## Examples
iex> 5 |> time? {15, 33, 42}
iex> 5 |> time?({15, 33, 42})
true
"""
defmacro time?(term) do
quote do
is_tuple(unquote(term))
and (tuple_size(unquote(term)) == 3)
and is_integer(elem(unquote(term), 0))
and (elem(unquote(term), 0) |> within? 0, 23)
and (elem(unquote(term), 0) |> within?(0, 23))
and is_integer(elem(unquote(term), 1))
and (elem(unquote(term), 1) |> within? 0, 59)
and (elem(unquote(term), 1) |> within?(0, 59))
and is_integer(elem(unquote(term), 2))
and (elem(unquote(term), 2) |> within? 0, 59)
and (elem(unquote(term), 2) |> within?(0, 59))
end
end

Expand Down
8 changes: 4 additions & 4 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Guardsafe.Mixfile do
def project do
[
app: :guardsafe,
version: "0.4.0",
version: "0.5.0",
name: "Guardsafe",
source_url: "https://github.com/DevL/guardsafe",
homepage_url: "https://hex.pm/packages/guardsafe",
Expand Down Expand Up @@ -36,9 +36,9 @@ defmodule Guardsafe.Mixfile do

defp deps do
[
{:earmark, "~> 0.1", only: :dev},
{:ex_doc, "~> 0.10", only: :dev},
{:inch_ex, only: :docs}
{:earmark, "~> 0.2", only: :dev},
{:ex_doc, "~> 0.11", only: :dev},
{:inch_ex, ">= 0.4.0", only: :docs}
]
end
end
6 changes: 3 additions & 3 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%{"earmark": {:hex, :earmark, "0.1.19"},
"ex_doc": {:hex, :ex_doc, "0.11.1"},
%{"earmark": {:hex, :earmark, "0.2.1"},
"ex_doc": {:hex, :ex_doc, "0.11.3"},
"inch_ex": {:hex, :inch_ex, "0.4.0"},
"poison": {:hex, :poison, "1.5.0"}}
"poison": {:hex, :poison, "1.5.2"}}
10 changes: 5 additions & 5 deletions test/guardsafe_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ defmodule GuardsafeTest do
~w(atom binary bitstring boolean integer float function list map nil number pid port reference tuple
even odd
date datetime time)
|> Enum.each fn(type) ->
|> Enum.each(fn(type) ->
def unquote(String.to_atom "using_#{type}?")(term) when unquote(String.to_atom "#{type}?")(term), do: true
def unquote(String.to_atom "using_#{type}?")(term) when not unquote(String.to_atom "#{type}?")(term), do: false
end
end)
end

test "divisible_by?" do
Expand Down Expand Up @@ -55,13 +55,13 @@ defmodule GuardsafeTest do
end

test "function?" do
assert When.using_function?(fn -> end)
assert When.using_function?(fn -> nil end)
refute When.using_function?(:not_a_function)
end

test "function? with arity" do
assert When.using_function_with_arity?(fn(_) -> end)
refute When.using_function_with_arity?(fn -> end)
assert When.using_function_with_arity?(fn(_) -> nil end)
refute When.using_function_with_arity?(fn -> nil end)
end

test "integer?" do
Expand Down

0 comments on commit 47ec200

Please sign in to comment.