Skip to content

Commit

Permalink
Updates elixir version
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolevn committed Jul 2, 2019
1 parent 8a55771 commit da2ce19
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 36 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
### Breaking changes

- Now only support `elixir>=1.6`
- We now use `Jason` as the default `json` library

### Features

- You can configure `:json_module` to set `Poison`
- Updates dependencies

### Misc
Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ Elixir library to inflect Russian first, last, and middle names.

## Installation

The package can be installed
by adding `petrovich_elixir` to your list of dependencies in `mix.exs`:

```elixir
def deps do
[{:petrovich_elixir, "~> 0.1"}]
[
{:petrovich_elixir, "~> 1.0"}
]
end
```

Expand Down
3 changes: 3 additions & 0 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
# and its dependencies with the aid of the Mix.Config module.
use Mix.Config

config :petrovich_elixir,
json_codec: Jason

# We only use config for tests and development:
if Mix.env() == :test, do: import_config("test.exs")
if Mix.env() == :dev, do: import_config("dev.exs")
5 changes: 5 additions & 0 deletions config/test_poison.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use Mix.Config

# Configure Petrovich to use `rules` submodule:
config :petrovich_elixir,
json_codec: Poison
1 change: 1 addition & 0 deletions lib/petrovich.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ defmodule Petrovich do
> instrumental: творительный
>
> prepositional: предложный
"""

use Application
Expand Down
4 changes: 2 additions & 2 deletions lib/petrovich/parser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ defmodule Petrovich.Parser do
This module should not be used directly. Use `Petrovich` module instead.
"""

alias Petrovich.{NameStore, Applier, Detector}
alias Petrovich.Utils.ResultJoiner
alias Petrovich.{Applier, Detector, NameStore}
alias Petrovich.Exceptions.ParseException
alias Petrovich.Utils.ResultJoiner

@doc """
Parses name and gets modifiers for the given case.
Expand Down
27 changes: 12 additions & 15 deletions lib/petrovich/stores/base.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,40 +15,37 @@ defmodule Petrovich.Store do

quote location: :keep, bind_quoted: [options: options, caller: caller] do
@setting Keyword.get(options, :setting)
@app :petrovich_elixir

def start_link do
Agent.start_link(
fn ->
load_values()
end,
name: unquote(caller)
)
Agent.start_link(&load_values/0, name: unquote(caller))
end

def stop do
Agent.stop(unquote(caller))
end

def get(key) do
Agent.get(unquote(caller), fn state ->
Map.get(state, key)
end)
Agent.get(unquote(caller), &Map.get(&1, key))
end

def all do
Agent.get(unquote(caller), fn state ->
state
end)
Agent.get(unquote(caller), & &1)
end

defp load_values do
:petrovich_elixir
@app
|> Config.get_env(@setting)
|> File.read!()
|> Poison.decode!()
|> get_json_codec().decode!()
rescue
e in File.Error ->
raise RulesFileException, message: Exception.message(e)
reraise RulesFileException, System.stacktrace(),
message: Exception.message(e)
end

defp get_json_codec do
Config.get_env(@app, :json_codec)
end
end
end
Expand Down
11 changes: 7 additions & 4 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,15 @@ defmodule Petrovich.Mixfile do

defp deps do
[
{:poison, "~> 3.1"},
{:jason, "~> 1.1"},

# We used to have it as a primary json lib, now only use for tests:
{:poison, "~> 4.0", only: [:dev, :test]},

# Dev and test dependencies:
{:credo, "~> 0.8", only: [:dev, :test], runtime: false},
{:excoveralls, "~> 0.7", only: :test, runtime: false},
{:dialyxir, "~> 0.5", only: [:dev], runtime: false},
{:credo, "~> 1.1", only: [:dev, :test], runtime: false},
{:excoveralls, "~> 0.11", only: :test, runtime: false},
{:dialyxir, "~> 0.5", only: :dev, runtime: false},
{:ex_doc, ">= 0.0.0", only: :dev}
]
end
Expand Down
24 changes: 14 additions & 10 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
%{"bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm"},
"certifi": {:hex, :certifi, "1.2.1", "c3904f192bd5284e5b13f20db3ceac9626e14eeacfbb492e19583cf0e37b22be", [:rebar3], [], "hexpm"},
"credo": {:hex, :credo, "0.8.1", "137efcc99b4bc507c958ba9b5dff70149e971250813cbe7d4537ec7e36997402", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}], "hexpm"},
%{
"bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm"},
"certifi": {:hex, :certifi, "2.5.1", "867ce347f7c7d78563450a18a6a28a8090331e77fa02380b4a21962a65d36ee5", [], [{:parse_trans, "~>3.3", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm"},
"credo": {:hex, :credo, "1.1.0", "e0c07b2fd7e2109495f582430a1bc96b2c71b7d94c59dfad120529f65f19872f", [], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm"},
"dialyxir": {:hex, :dialyxir, "0.5.0", "5bc543f9c28ecd51b99cc1a685a3c2a1a93216990347f259406a910cf048d1d7", [:mix], [], "hexpm"},
"earmark": {:hex, :earmark, "1.2.2", "f718159d6b65068e8daeef709ccddae5f7fdc770707d82e7d126f584cd925b74", [:mix], [], "hexpm"},
"ex_doc": {:hex, :ex_doc, "0.16.1", "b4b8a23602b4ce0e9a5a960a81260d1f7b29635b9652c67e95b0c2f7ccee5e81", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"},
"excoveralls": {:hex, :excoveralls, "0.7.0", "05cb3332c2b0f799df3ab90eb7df1ae5a147c86776e91792848a12b7ed87242f", [:mix], [{:exjsx, ">= 3.0.0", [hex: :exjsx, repo: "hexpm", optional: false]}, {:hackney, ">= 0.12.0", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm"},
"excoveralls": {:hex, :excoveralls, "0.11.1", "dd677fbdd49114fdbdbf445540ec735808250d56b011077798316505064edb2c", [], [{:hackney, "~> 1.0", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm"},
"exjsx": {:hex, :exjsx, "4.0.0", "60548841e0212df401e38e63c0078ec57b33e7ea49b032c796ccad8cde794b5c", [:mix], [{:jsx, "~> 2.8.0", [hex: :jsx, repo: "hexpm", optional: false]}], "hexpm"},
"hackney": {:hex, :hackney, "1.8.6", "21a725db3569b3fb11a6af17d5c5f654052ce9624219f1317e8639183de4a423", [:rebar3], [{:certifi, "1.2.1", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "5.0.2", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.1", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm"},
"idna": {:hex, :idna, "5.0.2", "ac203208ada855d95dc591a764b6e87259cb0e2a364218f215ad662daa8cd6b4", [:rebar3], [{:unicode_util_compat, "0.2.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm"},
"hackney": {:hex, :hackney, "1.15.1", "9f8f471c844b8ce395f7b6d8398139e26ddca9ebc171a8b91342ee15a19963f4", [], [{:certifi, "2.5.1", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "6.0.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.4", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm"},
"idna": {:hex, :idna, "6.0.0", "689c46cbcdf3524c44d5f3dde8001f364cd7608a99556d8fbd8239a5798d4c10", [], [{:unicode_util_compat, "0.4.1", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm"},
"jason": {:hex, :jason, "1.1.2", "b03dedea67a99223a2eaf9f1264ce37154564de899fd3d8b9a21b1a6fd64afe7", [], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm"},
"jsx": {:hex, :jsx, "2.8.2", "7acc7d785b5abe8a6e9adbde926a24e481f29956dd8b4df49e3e4e7bcc92a018", [:mix, :rebar3], [], "hexpm"},
"meck": {:hex, :meck, "0.8.4", "59ca1cd971372aa223138efcf9b29475bde299e1953046a0c727184790ab1520", [:make, :rebar], [], "hexpm"},
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm"},
"mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [:rebar3], [], "hexpm"},
"mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [], [], "hexpm"},
"mock": {:hex, :mock, "0.2.1", "bfdba786903e77f9c18772dee472d020ceb8ef000783e737725a4c8f54ad28ec", [:mix], [{:meck, "~> 0.8.2", [hex: :meck, repo: "hexpm", optional: false]}], "hexpm"},
"ok_jose": {:hex, :ok_jose, "2.0.0", "f3ccaf78cb60785f8623efb797ff04f6272d7ff224ff2ab568c78f0ffb9cd117", [:mix], [], "hexpm"},
"poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm"},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.1", "28a4d65b7f59893bc2c7de786dec1e1555bd742d336043fe644ae956c3497fbe", [:make, :rebar], [], "hexpm"},
"unicode_util_compat": {:hex, :unicode_util_compat, "0.2.0", "dbbccf6781821b1c0701845eaf966c9b6d83d7c3bfc65ca2b78b88b8678bfa35", [:rebar3], [], "hexpm"}}
"parse_trans": {:hex, :parse_trans, "3.3.0", "09765507a3c7590a784615cfd421d101aec25098d50b89d7aa1d66646bc571c1", [], [], "hexpm"},
"poison": {:hex, :poison, "4.0.1", "bcb755a16fac91cad79bfe9fc3585bb07b9331e50cfe3420a24bcc2d735709ae", [], [], "hexpm"},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.4", "f0eafff810d2041e93f915ef59899c923f4568f4585904d010387ed74988e77b", [], [], "hexpm"},
"unicode_util_compat": {:hex, :unicode_util_compat, "0.4.1", "d869e4c68901dd9531385bb0c8c40444ebf624e60b6962d95952775cac5e90cd", [], [], "hexpm"},
}
2 changes: 1 addition & 1 deletion test/petrovich_test/exceptions_test.exs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
defmodule PetrovichTest.Exceptions.ParseExceptionTest do
use ExUnit.Case

alias Petrovich.Parser
alias Petrovich.Exceptions.ParseException
alias Petrovich.Parser

test "raise ParseException" do
assert_raise ParseException, fn ->
Expand Down
13 changes: 13 additions & 0 deletions test/petrovich_test/poison_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
defmodule PetrovichTest.PoisonTest do
use ExUnit.Case

setup do
Mix.Config.eval!("config/test_poison.exs")
:ok
end

test "public firstname function works" do
assert Petrovich.firstname("Александр", :accusative, :male) ==
{:ok, "Александра"}
end
end

0 comments on commit da2ce19

Please sign in to comment.