Skip to content

Commit

Permalink
Merge branch 'develop' into fix/multiline-translations
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-swiatek committed Sep 20, 2024
2 parents 8bf2ccf + 6591b32 commit eb50bd6
Show file tree
Hide file tree
Showing 27 changed files with 231 additions and 325 deletions.
3 changes: 0 additions & 3 deletions .envrc

This file was deleted.

69 changes: 39 additions & 30 deletions .github/workflows/development.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,49 +13,58 @@ permissions:
contents: read

jobs:
test:
runs-on: ubuntu-latest
name: Test on OTP ${{matrix.otp}} / Elixir ${{matrix.elixir}}
build:
name: OS ${{matrix.os}} / Elixir ${{matrix.elixir}} / OTP ${{matrix.otp}}
strategy:
matrix:
otp: ["25.0.4"]
elixir: ["1.14.1"]
elixir: ['1.14', '1.15', '1.16', '1.17']
otp: ['24', '25', '26', '27']
os: [ubuntu-24.04]
exclude:
# Elixir 1.14
- elixir: '1.14'
otp: '27'
# Elixir 1.15
- elixir: '1.15'
otp: '27'
# Elixir 1.16
- elixir: '1.16'
otp: '27'
# Elixir 1.17
- elixir: '1.17'
otp: '24'
runs-on: ${{matrix.os}}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Elixir
uses: erlef/setup-beam@v1
with:
otp-version: ${{matrix.otp}}
elixir-version: ${{matrix.elixir}}
- name: Checkout code
uses: actions/checkout@v3
- name: Cache deps
id: cache-deps
uses: actions/cache@v3
env:
cache-name: cache-elixir-deps
- name: Restore dependencies cache
uses: actions/cache@v4
with:
path: deps
key: ${{ runner.os }}-mix-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }}
restore-keys: |
${{ runner.os }}-mix-${{ env.cache-name }}-
- name: Cache compiled build
id: cache-build
uses: actions/cache@v3
env:
cache-name: cache-compiled-build
with:
path: _build
key: ${{ runner.os }}-mix-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }}
restore-keys: |
${{ runner.os }}-mix-${{ env.cache-name }}-
${{ runner.os }}-mix-
key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }}
restore-keys: ${{ runner.os }}-mix-
- name: Set up Postgres
run: |
sudo apt-get update
sudo apt-get install -y postgresql
sudo service postgresql start
sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD 'postgres';"
- name: Install dependencies
run: mix deps.get
- name: Compiles without warnings
- name: Create database
run: mix do ecto.create, ecto.migrate
- name: Compile code
run: mix compile --warnings-as-errors
- name: Check Formatting
run: mix format --check-formatted
- name: Run credo
- name: Dialyzer
run: mix dialyzer -Wno_match --format short 2>&1
- name: Credo
run: mix credo
- name: "Run dialyzer"
run: mix dialyzer -Wno_match --format short 2>&1
- name: Run tests
run: MIX_ENV=test mix test
5 changes: 0 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,4 @@ kanta-*.tar
/assets/node_modules
/assets/.DS_Store
/.DS_Store
/.devenv.flake.nix
/.devenv/
/.direnv/
/.nix-mix/
/.nix-hex/
.DS_Store
156 changes: 0 additions & 156 deletions devenv.lock

This file was deleted.

34 changes: 0 additions & 34 deletions devenv.nix

This file was deleted.

3 changes: 0 additions & 3 deletions devenv.yaml

This file was deleted.

29 changes: 27 additions & 2 deletions lib/kanta/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ defmodule Kanta.Config do
repo: module(),
endpoint: module(),
plugins: false | [module() | {module() | Keyword.t()}],
disable_api_authorization: boolean()
disable_api_authorization: boolean(),
id_parse_function: mfa() | (term() -> {:ok, term()} | term())
}

defstruct name: Kanta,
otp_name: nil,
repo: nil,
endpoint: nil,
plugins: [],
disable_api_authorization: false
disable_api_authorization: false,
id_parse_function: {Kanta.Utils.ParamParsers, :default_id_parser, 1}

alias Kanta.Validator

Expand Down Expand Up @@ -82,6 +84,29 @@ defmodule Kanta.Config do
end
end

defp validate_opt(_opts, {:id_parse_function, {module, function, 1} = id_parse_function}) do
if Code.ensure_loaded?(module) and Kernel.function_exported?(module, function, 1) do
:ok
else
{:error,
"expected :id_parse_function to be a function with arity of 1, got: #{inspect(id_parse_function)}"}
end
end

defp validate_opt(_opts, {:id_parse_function, {_module, _function, _arity} = id_parse_function}) do
{:error,
"expected :id_parse_function to be a function with arity of 1, got: #{inspect(id_parse_function)}"}
end

defp validate_opt(_opts, {:id_parse_function, id_parse_function}) do
if is_function(id_parse_function, 1) do
:ok
else
{:error,
"expected :id_parse_function to be a function with arity of 1, got: #{inspect(id_parse_function)}"}
end
end

defp validate_opt(_opts, option) do
{:unknown, option, __MODULE__}
end
Expand Down
13 changes: 13 additions & 0 deletions lib/kanta/schema.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
defmodule Kanta.Schema do
@moduledoc false

defmacro __using__(_opts) do
quote do
use Ecto.Schema

@primary_key {:id, Application.compile_env(:kanta, :schema_id_type, :id),
autogenerate: true}
@foreign_key_type Application.compile_env(:kanta, :schema_id_type, :id)
end
end
end
2 changes: 1 addition & 1 deletion lib/kanta/translations/context.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule Kanta.Translations.Context do
Gettext Context DB model
"""

use Ecto.Schema
use Kanta.Schema
import Ecto.Changeset

alias Kanta.Translations.Message
Expand Down
2 changes: 1 addition & 1 deletion lib/kanta/translations/domain.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule Kanta.Translations.Domain do
Gettext domain DB model
"""

use Ecto.Schema
use Kanta.Schema
import Ecto.Changeset

alias Kanta.Translations.Message
Expand Down
2 changes: 1 addition & 1 deletion lib/kanta/translations/locale.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule Kanta.Translations.Locale do
Locale DB model
"""

use Ecto.Schema
use Kanta.Schema
import Ecto.Changeset
alias Kanta.Translations.SingularTranslation

Expand Down
2 changes: 1 addition & 1 deletion lib/kanta/translations/message.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule Kanta.Translations.Message do
Gettext message DB model
"""

use Ecto.Schema
use Kanta.Schema
import Ecto.Changeset

alias Kanta.Translations.{Context, Domain, PluralTranslation, SingularTranslation}
Expand Down
Loading

0 comments on commit eb50bd6

Please sign in to comment.