Skip to content

Commit

Permalink
Bucket names can be any Erlang term, #17
Browse files Browse the repository at this point in the history
  • Loading branch information
denvera authored and grempe committed Jun 23, 2020
1 parent 04440fc commit 744c14c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ to use ExRated in your own API. Its fast and its easy.

Call the ExRated application with `ExRated.check_rate/3`. This function takes three arguments:

1. A `bucket name` (String). You can have as many buckets as you need.
1. A `bucket name` (Erlang term, typically String). You can have as many buckets as you need.
2. A `scale` (Integer). The time scale in milliseconds that the bucket is valid for.
3. A `limit` (Integer). How many actions you want to limit your app to in the time scale provided.

Expand Down
8 changes: 4 additions & 4 deletions lib/ex_rated.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ defmodule ExRated do
## Arguments:
- `id` (String) name of the bucket
- `id` (Erlang term()) name of the bucket
- `scale` (Integer) of time in ms until the bucket rolls over. (e.g. 60_000 = empty bucket every minute)
- `limit` (Integer) the max size of a counter the bucket can hold.
Expand All @@ -46,7 +46,7 @@ defmodule ExRated do
{:ok, 1}
"""
@spec check_rate(id::String.t, scale::integer, limit::integer) :: {:ok, count::integer} | {:error, limit::integer}
@spec check_rate(id::any, scale::integer, limit::integer) :: {:ok, count::integer} | {:error, limit::integer}
def check_rate(id, scale, limit) do
ets_table_name = ets_table_name()
count_hit(id, scale, limit, ets_table_name)
Expand All @@ -59,7 +59,7 @@ defmodule ExRated do
## Arguments:
- `id` (String) name of the bucket
- `id` (Erlang term()) name of the bucket
- `scale` (Integer) of time the bucket you want to inspect was created with.
- `limit` (Integer) representing the max counter size the bucket was created with.
Expand All @@ -73,7 +73,7 @@ defmodule ExRated do
{1, 2499, 29381612, 1450281014468, 1450281014468}
"""
@spec inspect_bucket(id::String.t, scale::integer, limit::integer) :: {count::integer,
@spec inspect_bucket(id::any, scale::integer, limit::integer) :: {count::integer,
count_remaining::integer,
ms_to_next_bucket::integer,
created_at :: integer | nil,
Expand Down
1 change: 1 addition & 0 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ defmodule ExRated.Mixfile do
name: "ExRated",
source_url: "https://github.com/grempe/ex_rated",
homepage_url: "https://github.com/grempe/ex_rated",
aliases: [test: "test --no-start"],
docs: [extras: ["README.md"]]]
end

Expand Down
6 changes: 6 additions & 0 deletions test/ex_rated_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ defmodule ExRatedServerTest do
ExRated.stop(pid)
end

test "bucket names can be any()" do
Enum.each([true, nil, :atom, %{map: :type}, self(), {:a, 5, "x"}, 0.1, 5, ["a", "b"]], fn e ->
assert {:ok, 1} = ExRated.check_rate(e, 10000, 10)
end)
end

defp start_server(_table, persistent) do
GenServer.start_link(ExRated, [
{:timeout, 10_000},
Expand Down

0 comments on commit 744c14c

Please sign in to comment.