Skip to content

Commit

Permalink
Overall fixes and enhancements including support for Elixir 1.13.x
Browse files Browse the repository at this point in the history
  • Loading branch information
cabol committed Apr 18, 2022
1 parent fd93116 commit 9bf4898
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 28 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ jobs:
- elixir: 1.11.x
otp: 23.x
inch-report: true
- elixir: 1.9.x
otp: 22.x

env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
Expand Down Expand Up @@ -98,7 +96,7 @@ jobs:
path: priv/plts
key: >-
${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-plts-${{
hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}-v0
hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}-v1
if: ${{ matrix.dialyzer }}

- name: Create PLTs
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@ Partitioned | [Nebulex.Adapters.Partitioned][pa] | Built-In
Replicated | [Nebulex.Adapters.Replicated][ra] | Built-In
Multilevel | [Nebulex.Adapters.Multilevel][ma] | Built-In
Nil (special adapter that disables the cache) | [Nebulex.Adapters.Nil][nil] | Built-In
Cachex | Nebulex.Adapters.Cachex | [nebulex_adapters_cachex][nbx_cachex]
Redis | NebulexRedisAdapter | [nebulex_redis_adapter][nbx_redis]
Cachex | Nebulex.Adapters.Cachex | [nebulex_adapters_cachex][nbx_cachex]

[la]: http://hexdocs.pm/nebulex/Nebulex.Adapters.Local.html
[pa]: http://hexdocs.pm/nebulex/Nebulex.Adapters.Partitioned.html
[ra]: http://hexdocs.pm/nebulex/Nebulex.Adapters.Replicated.html
[ma]: http://hexdocs.pm/nebulex/Nebulex.Adapters.Multilevel.html
[nil]: http://hexdocs.pm/nebulex/Nebulex.Adapters.Nil.html
[nbx_cachex]: https://github.com/cabol/nebulex_adapters_cachex
[nbx_redis]: https://github.com/cabol/nebulex_redis_adapter
[nbx_cachex]: https://github.com/cabol/nebulex_adapters_cachex

For example, if you want to use a built-in cache, add to your `mix.exs` file:

Expand Down
1 change: 1 addition & 0 deletions coveralls.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
},

"skip_files": [
"lib/nebulex/cache/options.ex",
"test/support/*",
"test/dialyzer/*"
]
Expand Down
6 changes: 4 additions & 2 deletions lib/nebulex/adapter/persistence.ex
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ defmodule Nebulex.Adapter.Persistence do

import Nebulex.Helpers

# sobelow_skip ["Traversal.FileModule"]
@impl true
def dump(%{cache: cache}, path, opts) do
with_file(path, [:read, :write], fn io_dev ->
Expand All @@ -64,13 +63,13 @@ defmodule Nebulex.Adapter.Persistence do
|> Stream.chunk_every(Keyword.get(opts, :entries_per_line, 10))
|> Enum.each(fn entries ->
bin = Entry.encode(entries, get_compression(opts))

:ok = IO.puts(io_dev, bin)
end)
end
end)
end

# sobelow_skip ["Traversal.FileModule"]
@impl true
def load(%{cache: cache}, path, opts) do
with_file(path, [:read], fn io_dev ->
Expand All @@ -79,6 +78,7 @@ defmodule Nebulex.Adapter.Persistence do
|> Stream.map(&String.trim/1)
|> Enum.each(fn line ->
entries = Entry.decode(line, [:safe])

cache.put_all(entries, opts)
end)
end)
Expand All @@ -88,6 +88,7 @@ defmodule Nebulex.Adapter.Persistence do

## Helpers

# sobelow_skip ["Traversal.FileModule"]
defp with_file(path, modes, function) do
case File.open(path, modes) do
{:ok, io_device} ->
Expand All @@ -99,6 +100,7 @@ defmodule Nebulex.Adapter.Persistence do

{:error, reason} ->
reason = %File.Error{reason: reason, action: "open", path: path}

wrap_error Nebulex.Error, reason: reason
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/nebulex/adapter/transaction.ex
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ defmodule Nebulex.Adapter.Transaction do
true ->
try do
_ = Process.put({pid, self()}, %{keys: keys, nodes: nodes})

{:ok, fun.()}
after
_ = Process.delete({pid, self()})
Expand Down
1 change: 1 addition & 0 deletions lib/nebulex/cache/supervisor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ defmodule Nebulex.Cache.Supervisor do
"""
def start_link(cache, otp_app, adapter, opts) do
sup_opts = if name = Keyword.get(opts, :name, cache), do: [name: name], else: []

Supervisor.start_link(__MODULE__, {cache, otp_app, adapter, opts}, sup_opts)
end

Expand Down
12 changes: 9 additions & 3 deletions lib/nebulex/caching.ex
Original file line number Diff line number Diff line change
Expand Up @@ -728,17 +728,20 @@ if Code.ensure_loaded?(Decorator.Define) do
**NOTE:** Internal purposes only.
"""
@spec eval_cache_evict(boolean, boolean, module, keygen, [term], on_error, fun) :: term
@spec eval_cache_evict(boolean, boolean, module, keygen, [term] | nil, on_error, fun) :: term
def eval_cache_evict(before_invocation?, all_entries?, cache, keygen, keys, on_error, block_fun)

def eval_cache_evict(true, all_entries?, cache, keygen, keys, on_error, block_fun) do
_ = do_evict(all_entries?, cache, keygen, keys, on_error)

block_fun.()
end

def eval_cache_evict(false, all_entries?, cache, keygen, keys, on_error, block_fun) do
result = block_fun.()

_ = do_evict(all_entries?, cache, keygen, keys, on_error)

result
end

Expand All @@ -765,10 +768,12 @@ if Code.ensure_loaded?(Decorator.Define) do
case match.(result) do
{true, value} ->
_ = run_cmd(__MODULE__, :cache_put, [cache, key, value, opts], on_error)

result

true ->
_ = run_cmd(__MODULE__, :cache_put, [cache, key, result, opts], on_error)

result

false ->
Expand All @@ -785,8 +790,9 @@ if Code.ensure_loaded?(Decorator.Define) do
def cache_put(cache, key, value, opts)

def cache_put(cache, {:"$keys", keys}, value, opts) do
entries = for k <- keys, do: {k, value}
cache.put_all(entries, opts)
keys
|> Enum.map(&{&1, value})
|> cache.put_all(opts)
end

def cache_put(cache, key, value, opts) do
Expand Down
21 changes: 5 additions & 16 deletions lib/nebulex/helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,6 @@ defmodule Nebulex.Helpers do
end
end

@spec get_boolean_option(keyword, atom, boolean) :: term
def get_boolean_option(opts, key, default \\ false)
when is_list(opts) and is_atom(key) and is_boolean(default) do
value = Keyword.get(opts, key, default)

if is_boolean(value) do
value
else
raise ArgumentError, "expected #{key}: to be boolean, got: #{inspect(value)}"
end
end

@spec assert_behaviour(module, module, binary) :: module
def assert_behaviour(module, behaviour, msg \\ "module") do
if behaviour in module_behaviours(module, msg) do
Expand Down Expand Up @@ -70,15 +58,14 @@ defmodule Nebulex.Helpers do
end
end

# FIXME: this is because coveralls does not mark this as covered
# coveralls-ignore-start

@doc false
defmacro wrap_ok(call) do
# FIXME: this is because coveralls does not mark this as covered
# coveralls-ignore-start
quote do
{:ok, unquote(call)}
end

# coveralls-ignore-stop
end

@doc false
Expand All @@ -87,4 +74,6 @@ defmodule Nebulex.Helpers do
{:error, unquote(exception).exception(unquote(opts))}
end
end

# coveralls-ignore-stop
end
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule Nebulex.MixProject do
use Mix.Project

@source_url "https://github.com/cabol/nebulex"
@version "2.3.2"
@version "3.0.0-dev"

def project do
[
Expand Down
2 changes: 1 addition & 1 deletion mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm", "f278585650aa581986264638ebf698f8bb19df297f66ad91b18910dfc6e19323"},
"mock": {:hex, :mock, "0.3.7", "75b3bbf1466d7e486ea2052a73c6e062c6256fb429d6797999ab02fa32f29e03", [:mix], [{:meck, "~> 0.9.2", [hex: :meck, repo: "hexpm", optional: false]}], "hexpm", "4da49a4609e41fd99b7836945c26f373623ea968cfb6282742bcb94440cf7e5c"},
"nimble_options": {:hex, :nimble_options, "0.4.0", "c89babbab52221a24b8d1ff9e7d838be70f0d871be823165c94dd3418eea728f", [:mix], [], "hexpm", "e6701c1af326a11eea9634a3b1c62b475339ace9456c1a23ec3bc9a847bca02d"},
"nimble_parsec": {:hex, :nimble_parsec, "1.2.2", "b99ca56bbce410e9d5ee4f9155a212e942e224e259c7ebbf8f2c86ac21d4fa3c", [:mix], [], "hexpm", "98d51bd64d5f6a2a9c6bb7586ee8129e27dfaab1140b5a4753f24dac0ba27d2f"},
"nimble_parsec": {:hex, :nimble_parsec, "1.2.3", "244836e6e3f1200c7f30cb56733fd808744eca61fd182f731eac4af635cc6d0b", [:mix], [], "hexpm", "c8d789e39b9131acf7b99291e93dae60ab48ef14a7ee9d58c6964f59efb570b0"},
"parse_trans": {:hex, :parse_trans, "3.3.1", "16328ab840cc09919bd10dab29e431da3af9e9e7e7e6f0089dd5a2d2820011d8", [:rebar3], [], "hexpm", "07cd9577885f56362d414e8c4c4e6bdf10d43a8767abb92d24cbe8b24c54888b"},
"shards": {:hex, :shards, "1.0.1", "1bdbbf047db27f3c3eb800a829d4a47062c84d5543cbfebcfc4c14d038bf9220", [:make, :rebar3], [], "hexpm", "2c57788afbf053c4024366772892beee89b8b72e884e764fb0a075dfa7442041"},
"sobelow": {:hex, :sobelow, "0.11.1", "23438964486f8112b41e743bbfd402da3e5b296fdc9eacab29914b79c48916dd", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "9897363a7eff96f4809304a90aad819e2ad5e5d24db547af502885146746a53c"},
Expand Down

0 comments on commit 9bf4898

Please sign in to comment.