Skip to content

Commit

Permalink
use Keyword.pop/3 with default value instead of Keyword.pop!/2
Browse files Browse the repository at this point in the history
  • Loading branch information
woylie committed Nov 6, 2022
1 parent 22abb32 commit fb1f595
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

## Unreleased

## [1.0.1] - 2022-11-06

### Changed

- Use `Keyword.pop/3` with default value instead of `Keyword.pop!/2`, so that
you can pass options to `LetMe.redact/3` without passing the `redact_value`
option.

## [1.0.0] - 2022-11-06

### Added
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Add LetMe to `mix.exs` :
```elixir
def deps do
[
{:let_me, "~> 1.0.0"}
{:let_me, "~> 1.0.1"}
]
end
```
Expand Down
6 changes: 3 additions & 3 deletions lib/let_me.ex
Original file line number Diff line number Diff line change
Expand Up @@ -183,17 +183,17 @@ defmodule LetMe do
@spec redact(struct, any, keyword) :: struct
@spec redact([struct], any, keyword) :: [struct]
@spec redact(nil, any, keyword) :: nil
def redact(struct, subject, opts \\ [redact_value: :redacted])
def redact(struct, subject, opts \\ [])

def redact(objects, subject, opts) when is_list(objects) do
{redact_value, opts} = Keyword.pop!(opts, :redact_value)
{redact_value, opts} = Keyword.pop(opts, :redact_value, :redacted)
Enum.map(objects, &do_redact(&1, subject, redact_value, opts))
end

def redact(nil, _, _), do: nil

def redact(object, subject, opts) do
{redact_value, opts} = Keyword.pop!(opts, :redact_value)
{redact_value, opts} = Keyword.pop(opts, :redact_value, :redacted)
do_redact(object, subject, redact_value, opts)
end

Expand Down
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 LetMe.MixProject do
use Mix.Project

@source_url "https://github.com/woylie/let_me"
@version "1.0.0"
@version "1.0.1"

def project do
[
Expand Down

0 comments on commit fb1f595

Please sign in to comment.