Skip to content

Commit

Permalink
Fix names clashing issue
Browse files Browse the repository at this point in the history
There was names clashing issue when we use variables with the same name
that exometer id already has.

See xerions#23
  • Loading branch information
surik committed Jul 28, 2016
1 parent e408d43 commit ce8a7ae
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions lib/subscription.ex
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ defmodule Metricman.Subscription do
("$" <> id, ids) -> ids ++ [{id |> to_downcased_atom, [], Elixir}]
(id, ids) -> ids ++ [id] end)
vars = List.foldl(exo_id, [],
fn ([?$ | id], acc) -> acc ++ [id |> to_downcased_atom]
("$" <> id, acc) -> acc ++ [id |> to_downcased_atom]
fn ([?$ | _] = id, acc) -> acc ++ [id |> to_downcased_atom]
("$" <> _ = id, acc) -> acc ++ [id |> to_downcased_atom]
(_, acc) -> acc ++ [:_]
end)
quote do
Expand All @@ -107,8 +107,8 @@ defmodule Metricman.Subscription do
|> Enum.zip(unquote(exo_id_for_match))
|> Enum.filter(fn({x, _}) -> x != :_ end)
path = List.foldl(@path ++ unquote(id), [],
fn ([?$ | id], acc) -> acc ++ [id |> to_downcased_atom]
("$" <> id, acc) -> acc ++ [id |> to_downcased_atom]
fn ([?$ | _] = id, acc) -> acc ++ [id |> to_downcased_atom]
("$" <> _ = id, acc) -> acc ++ [id |> to_downcased_atom]
(id, acc) -> acc ++ [id]
end)
opts = Keyword.merge(@opts, unquote(opts))
Expand Down
8 changes: 4 additions & 4 deletions test/subscription_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ defmodule MetricmanSubscribtionTest do
map [:used], [:ippools, :ip, :total, :used]
map [:total], [:ippools, :ip, :total, :total], @opts2
scope ['$country'] do
scope [:region, "$city"] do # it is posible to use list and string as variable name
map [:used], [:ippools, :ip, '$country', '$city', :used]
map [:total], [:ippools, :ip, "$country", "$city", :total]
map [:func], [:ippools, :ip, "$country", "$city", :func]
scope [:region, "$region"] do # it is posible to use list and string as variable name
map [:used], [:ippools, :ip, '$country', '$region', :used]
map [:total], [:ippools, :ip, "$country", "$region", :total]
map [:func], [:ippools, :ip, "$country", "$region", :func]
end
map [:used], [:ippools, :ip, '$country', :used]
map [:total], [:ippools, :ip, '$country', :total]
Expand Down

0 comments on commit ce8a7ae

Please sign in to comment.