-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* also allow poison 2.0 as dep problem: - some project use already poison 2.0 (or 2.1), verk installation does not work there solution: - also allow poison 2.0 by relaxing dependency ``` { :poison, "~> 1.5 or ~> 2.0"}, ``` * different json decoding based on Poison version problem: - Poison >2.0 changed the way it accepts `as` params ``` https://github.com/devinus/poison If you use Poison 1.x, you have to set a module to as option in order to decode into a struct. e.g. as: Person instead of as: %Person{}. The change was introduced at 2.0.0. ``` - we want to stay compatible with Poison < 2.0 and > 2.0 solution: - read the current Poison version during compilation time and switch encoding logic based on whether we are before 2.0 or after.
- Loading branch information
1 parent
7825039
commit b18b20e
Showing
3 changed files
with
28 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
defmodule Verk.PoisonVersion do | ||
defmacro __using__(_) do | ||
quote do | ||
def poison_version do | ||
unquote(Verk.PoisonVersion.runtime_poison_version) | ||
end | ||
|
||
def is_before_poison_2 do | ||
unquote(Verk.PoisonVersion.runtime_poison_version) |> Version.match?("<2.0.0") | ||
end | ||
end | ||
end | ||
|
||
def runtime_poison_version do | ||
Mix.Project.config | ||
|> Keyword.get(:deps) | ||
|> Mix.Dep.loaded | ||
|> Enum.find(fn(%{app: app})-> app == :poison end) | ||
|> Map.get(:status) | ||
|> elem(1) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters