Skip to content

Commit

Permalink
Drop aliases #159
Browse files Browse the repository at this point in the history
  • Loading branch information
teamon committed Jan 26, 2018
1 parent fec8b6c commit 5ed79f0
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 37 deletions.
4 changes: 2 additions & 2 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# and its dependencies with the aid of the Mix.Config module.
use Mix.Config

config :tesla, adapter: :httpc
config :tesla, adapter: Tesla.Adapter.Httpc

config :logger, :console,
level: :debug,
Expand All @@ -18,5 +18,5 @@ if Mix.env == :test do
errlog_type: :error,
sasl_error_logger: false

config :tesla, MockClient, adapter: :mock
config :tesla, MockClient, adapter: Tesla.Mock
end
33 changes: 2 additions & 31 deletions lib/tesla.ex
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ defmodule Tesla.Builder do
"""
defmacro plug(middleware, opts \\ nil) do
opts = Macro.escape(opts)
middleware = Tesla.alias(middleware)
quote do: @__middleware__({unquote(middleware), unquote(opts)})
end

Expand Down Expand Up @@ -194,7 +193,6 @@ defmodule Tesla.Builder do
end

defmacro adapter(adapter, opts \\ nil) do
adapter = Tesla.alias(adapter)
quote do: @__adapter__({unquote(adapter), unquote(opts)})
end

Expand Down Expand Up @@ -395,33 +393,6 @@ defmodule Tesla do
end
end

@aliases [
httpc: Tesla.Adapter.Httpc,
hackney: Tesla.Adapter.Hackney,
ibrowse: Tesla.Adapter.Ibrowse,
mock: Tesla.Mock,
base_url: Tesla.Middleware.BaseUrl,
headers: Tesla.Middleware.Headers,
query: Tesla.Middleware.Query,
opts: Tesla.Middleware.Opts,
follow_redirects: Tesla.Middleware.FollowRedirects,
method_override: Tesla.Middleware.MethodOverride,
logger: Tesla.Middleware.Logger,
debug_logger: Tesla.Middleware.DebugLogger,
form_urlencoded: Tesla.Middleware.FormUrlencoded,
json: Tesla.Middleware.JSON,
compression: Tesla.Middleware.Compression,
decode_rels: Tesla.Middleware.DecodeRels,
basic_auth: Tesla.Middleware.BasicAuth,
digest_auth: Tesla.Middleware.DigestAuth,
timeout: Tesla.Middleware.Timeout,
retry: Tesla.Middleware.Retry,
fuse: Tesla.Middleware.Fuse,
tuples: Tesla.Middleware.Tuples
]
def alias(key) when is_atom(key), do: Keyword.get(@aliases, key, key)
def alias(key), do: key

def perform_request(module, client \\ nil, options) do
%{fun: fun, pre: pre, post: post} = client || %Tesla.Client{}

Expand Down Expand Up @@ -473,11 +444,11 @@ defmodule Tesla do
end

defp module_adapter_from_config(module) do
Application.get_env(:tesla, module, [])[:adapter] |> Tesla.alias()
Application.get_env(:tesla, module, [])[:adapter]
end

def default_adapter do
Application.get_env(:tesla, :adapter, :httpc) |> Tesla.alias()
Application.get_env(:tesla, :adapter, Tesla.Adapter.Httpc)
end

def run_default_adapter(env, opts \\ []) do
Expand Down
4 changes: 2 additions & 2 deletions lib/tesla/mock.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ defmodule Tesla.Mock do
```
# config/test.exs
config :tesla, adapter: :mock
config :tesla, adapter: Tesla.Mock
# in case MyClient defines specific adapter with `adapter :specific`
config :tesla, MyClient, adapter: :mock
config :tesla, MyClient, adapter: Tesla.Mock
```
### Example test
Expand Down
4 changes: 2 additions & 2 deletions test/tesla_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,12 @@ defmodule TeslaTest do
end

test "use adapter override from config" do
Application.put_env(:tesla, EmptyClient, adapter: :mock)
Application.put_env(:tesla, EmptyClient, adapter: Tesla.Mock)
assert EmptyClient.__adapter__() == Tesla.Mock
end

test "prefer config over module setting" do
Application.put_env(:tesla, ModuleAdapterClient, adapter: :mock)
Application.put_env(:tesla, ModuleAdapterClient, adapter: Tesla.Mock)
assert ModuleAdapterClient.__adapter__() == Tesla.Mock
end
end
Expand Down

0 comments on commit 5ed79f0

Please sign in to comment.