From 76cfb574a3ecfd80f43ef9abe2017a081a6314a4 Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Fri, 21 Jun 2019 19:39:58 +0700 Subject: [PATCH] Remove application configuration --- config/config.exs | 30 ------------------------------ lib/auto_linker/parser.ex | 24 ++++++------------------ 2 files changed, 6 insertions(+), 48 deletions(-) delete mode 100644 config/config.exs diff --git a/config/config.exs b/config/config.exs deleted file mode 100644 index 78be4ed..0000000 --- a/config/config.exs +++ /dev/null @@ -1,30 +0,0 @@ -# This file is responsible for configuring your application -# and its dependencies with the aid of the Mix.Config module. -use Mix.Config - -# This configuration is loaded before any dependency and is restricted -# to this project. If another project depends on this project, this -# file won't be loaded nor affect the parent project. For this reason, -# if you want to provide default values for your application for -# 3rd-party users, it should be done in your "mix.exs" file. - -# You can configure for your application as: -# -# config :auto_linker, key: :value -# -# And access this configuration in your application as: -# -# Application.get_env(:auto_linker, :key) -# -# Or configure a 3rd-party app: -# -# config :logger, level: :info -# - -# It is also possible to import configuration files, relative to this -# directory. For example, you can emulate configuration per environment -# by uncommenting the line below and defining dev.exs, test.exs and such. -# Configuration from the imported file will override the ones defined -# here (which is why it is important to import them last). -# -# import_config "#{Mix.env}.exs" diff --git a/lib/auto_linker/parser.ex b/lib/auto_linker/parser.ex index bf02cac..a427888 100644 --- a/lib/auto_linker/parser.ex +++ b/lib/auto_linker/parser.ex @@ -38,7 +38,10 @@ defmodule AutoLinker.Parser do @tlds "./priv/tlds.txt" |> File.read!() |> String.split("\n", trim: true) |> MapSet.new() - @default_opts ~w(url validate_tld)a + @default_opts %{ + url: true, + validate_tld: true + } @doc """ Parse the given string, identifying items to link. @@ -52,27 +55,12 @@ defmodule AutoLinker.Parser do """ def parse(input, opts \\ %{}) - def parse(input, opts) when is_binary(input), do: {input, nil} |> parse(opts) |> elem(0) + def parse(input, opts) when is_binary(input), do: {input, %{}} |> parse(opts) |> elem(0) def parse(input, list) when is_list(list), do: parse(input, Enum.into(list, %{})) def parse(input, opts) do - config = - :auto_linker - |> Application.get_env(:opts, []) - |> Enum.into(%{}) - |> Map.put( - :attributes, - Application.get_env(:auto_linker, :attributes, []) - ) + opts = Map.merge(@default_opts, opts) - opts = - Enum.reduce(@default_opts, opts, fn opt, acc -> - if is_nil(opts[opt]) and is_nil(config[opt]) do - Map.put(acc, opt, true) - else - acc - end - end) do_parse(input, Map.merge(config, opts)) end