Skip to content

File tree

7 files changed

+59
-18
lines changed

7 files changed

+59
-18
lines changed

CHANGELOG.md

+18
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
# Changelog for MishkaDeveloperTools 0.1.7
2+
3+
> Kindly ensure that the macro is updated as quickly as feasible. This version includes a bug patch in the macro kernel that eliminates the issue of not being able to build in projects.
4+
5+
In the past, it was possible to extend validation and sanitizer functions within the macro itself; however, this was a relatively insignificant addition that was ultimately overwritten. The same opportunity will now be available to you if you include environment in the project.
6+
7+
### For example:
8+
```elixir
9+
Application.put_env(:guarded_struct, :validate_derive, [TestValidate, TestValidate2])
10+
Application.put_env(:guarded_struct, :sanitize_derive, [TestSanitize, TestSanitize2])
11+
12+
# OR
13+
Application.put_env(:guarded_struct, :validate_derive, TestValidate)
14+
Application.put_env(:guarded_struct, :sanitize_derive, TestSanitize)
15+
```
16+
17+
I offer my heartfelt apologies for the occurrence of this bug and express my desire to encounter less similar challenges in the future.
18+
119
# Changelog for MishkaDeveloperTools 0.1.6
220

321
### Features:

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ The package can be installed by adding `mishka_developer_tools` to your list of
3131
```elixir
3232
def deps do
3333
[
34-
{:mishka_developer_tools, "~> 0.1.6"}
34+
{:mishka_developer_tools, "~> 0.1.7"}
3535
]
3636
end
3737
```

guidance/guarded-struct.livemd

+16-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
```elixir
44
Mix.install([
5-
{:mishka_developer_tools, github: "mishka-group/mishka_developer_tools"},
5+
{:mishka_developer_tools, "~> 0.1.7"}
66
# Optional dependencies
77
{:html_sanitize_ex, "~> 1.4.3"},
88
{:email_checker, "~> 0.2.4"},
@@ -343,6 +343,7 @@ As the code sample above illustrates. `main_validator` is a bit rudimentary in t
343343
| `"sanitize(strip_tags)"` | `:html_sanitize_ex` | Sanitize your string base on `strip_tags` |
344344
| `"sanitize(tag)"` | `:html_sanitize_ex` | Sanitize your string base on `html_sanitize_ex` selection |
345345
| `"sanitize(string_float)"` | `:html_sanitize_ex` or NO | Sanitize your string base on `html_sanitize_ex` and `Float.parse/1` |
346+
| `"sanitize(string_integer)"` | `:html_sanitize_ex` or NO | Sanitize your string base on `html_sanitize_ex` and `Integer.parse/1` |
346347

347348
#### Validate
348349

@@ -398,6 +399,9 @@ As the code sample above illustrates. `main_validator` is a bit rudimentary in t
398399
| `"validate(some_string_integer)"` | NO | Validate if the string data is integer (Somewhat by removing the string) |
399400
| `"validate(not_flatten_empty)"` | NO | Validate the list if it is empty by summing and flattening the entire list |
400401
| `"validate(not_flatten_empty_item)"` | NO | Validate the list if it is empty by summing and flattening the entire list and first level children |
402+
| `"validate(queue)"` | NO | Validate the data is Erlang queue or not |
403+
| `"validate(username)"` | NO | Validate the input has username format or not |
404+
| `"validate(full_name)"` | NO | Validate the input has full_name format or not |
401405

402406
```elixir
403407
defmodule NormalDeriveStruct do
@@ -429,6 +433,17 @@ NormalDeriveStruct.builder(%{title: :mishka})
429433
* `validate_derive` - It can be just one module or a list of modules
430434
* `sanitize_derive` - It can be just one module or a list of modules
431435

436+
- First set Application env:
437+
438+
```elixir
439+
Application.put_env(:guarded_struct, :validate_derive, [TestValidate, TestValidate2])
440+
Application.put_env(:guarded_struct, :sanitize_derive, [TestSanitize, TestSanitize2])
441+
442+
# OR
443+
Application.put_env(:guarded_struct, :validate_derive, TestValidate)
444+
Application.put_env(:guarded_struct, :sanitize_derive, TestSanitize)
445+
```
446+
432447
```elixir
433448
defmodule TestValidateModule do
434449
def validate(:testv1, input, field) do

lib/macros/guarded_struct/guarded_struct.ex

+16-7
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,8 @@ defmodule GuardedStruct do
332332
| `"sanitize(strip_tags)"` | `:html_sanitize_ex` | Sanitize your string base on `strip_tags` |
333333
| `"sanitize(tag)"` | `:html_sanitize_ex` | Sanitize your string base on `html_sanitize_ex` selection |
334334
| `"sanitize(string_float)"` | `:html_sanitize_ex` or `none` | Sanitize your string base on `html_sanitize_ex` and `Float.parse/1` |
335+
| `"sanitize(string_float)"` | `:html_sanitize_ex` or NO | Sanitize your string base on `html_sanitize_ex` and `Float.parse/1` |
336+
| `"sanitize(string_integer)"` | `:html_sanitize_ex` or NO | Sanitize your string base on `html_sanitize_ex` and `Integer.parse/1` |
335337
336338
#### Validate
337339
@@ -387,6 +389,9 @@ defmodule GuardedStruct do
387389
| `"validate(some_string_integer)"` | NO | Validate if the string data is integer (Somewhat by removing the string)|
388390
| `"validate(not_flatten_empty)"` | NO | Validate the list if it is empty by summing and flattening the entire list|
389391
| `"validate(not_flatten_empty_item)"` | NO | Validate the list if it is empty by summing and flattening the entire list and first level children|
392+
| `"validate(queue)"` | NO | Validate the data is Erlang queue or not |
393+
| `"validate(username)"` | NO | Validate the input has username format or not |
394+
| `"validate(full_name)"` | NO | Validate the input has full_name format or not |
390395
391396
```elixir
392397
defmodule MyModule do
@@ -408,6 +413,17 @@ defmodule GuardedStruct do
408413
* `validate_derive` - It can be just one module or a list of modules
409414
* `sanitize_derive` - It can be just one module or a list of modules
410415
416+
First set Application env:
417+
418+
```elixir
419+
Application.put_env(:guarded_struct, :validate_derive, [TestValidate, TestValidate2])
420+
Application.put_env(:guarded_struct, :sanitize_derive, [TestSanitize, TestSanitize2])
421+
422+
# OR
423+
Application.put_env(:guarded_struct, :validate_derive, TestValidate)
424+
Application.put_env(:guarded_struct, :sanitize_derive, TestSanitize)
425+
```
426+
411427
```elixir
412428
defmodule TestValidate do
413429
def validate(:testv1, input, field) do
@@ -1494,13 +1510,6 @@ defmodule GuardedStruct do
14941510
@doc false
14951511
def register_struct(block, opts, key, caller) do
14961512
quote do
1497-
[:validate_derive, :sanitize_derive]
1498-
|> Enum.each(fn item ->
1499-
if is_nil(Application.compile_env(:guarded_struct, item)) do
1500-
Application.put_env(:guarded_struct, item, Keyword.get(unquote(opts), item))
1501-
end
1502-
end)
1503-
15041513
Enum.each(unquote(@temporary_revaluation), fn attr ->
15051514
Module.register_attribute(__MODULE__, attr, accumulate: true)
15061515
end)

lib/mishka_developer_tools.ex

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ defmodule MishkaDeveloperTools do
44
55
We tried to deliver a series of our client's [**CMS**](https://github.com/mishka-group/mishka-cms) built on [**Elixir**](https://elixir-lang.org/) at the start of the [**Mishka Group**](https://github.com/mishka-group) project, but we recently archived this open-source project and have yet to make plans to rework and expand it. This system was created using [**Phoenix**](https://www.phoenixframework.org/) and [**Phoenix LiveView**](https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.html). After a long period, a series of macros and functional modules emerged from this project and our other projects, which we are gradually publishing in this library.
66
7-
> **NOTICE**: Do not use the master branch; this library is under heavy development. Expect version `0.1.6`, and for using the new features, please wait until a new release is out.
7+
> **NOTICE**: Do not use the master branch; this library is under heavy development. Expect version `0.1.7`, and for using the new features, please wait until a new release is out.
88
99
---
1010
@@ -33,7 +33,7 @@ defmodule MishkaDeveloperTools do
3333
```elixir
3434
def deps do
3535
[
36-
{:mishka_developer_tools, "~> 0.1.6"}
36+
{:mishka_developer_tools, "~> 0.1.7"}
3737
]
3838
end
3939
```

mix.exs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
defmodule MishkaDeveloperTools.MixProject do
22
use Mix.Project
3-
@version "0.1.6"
3+
@version "0.1.7"
44
@source_url "https://github.com/mishka-group/mishka_developer_tools"
55

66
def project do

test/guarded_struct_test/derive_test.exs

+5-6
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ defmodule MishkaDeveloperToolsTest.GuardedStructDeriveTest do
648648
defmodule TestExistCustomValidateDerive do
649649
use GuardedStruct
650650

651-
guardedstruct validate_derive: TestValidate, sanitize_derive: TestSanitize do
651+
guardedstruct do
652652
field(:id, integer(), derive: "validate(not_exist)")
653653
field(:title, String.t(), derive: "validate(string)")
654654
field(:name, String.t(), derive: "sanitize(capitalize_v2)")
@@ -658,7 +658,7 @@ defmodule MishkaDeveloperToolsTest.GuardedStructDeriveTest do
658658
defmodule TestCustomeDerive do
659659
use GuardedStruct
660660

661-
guardedstruct validate_derive: TestValidate, sanitize_derive: TestSanitize do
661+
guardedstruct do
662662
field(:id, integer())
663663
field(:title, String.t(), derive: "validate(not_empty, testv1)")
664664
field(:name, String.t(), derive: "validate(string, not_empty) sanitize(trim, capitalize)")
@@ -701,14 +701,13 @@ defmodule MishkaDeveloperToolsTest.GuardedStructDeriveTest do
701701
]} = assert TestCustomeDerive.builder(%{id: 1, title: 1})
702702
end
703703

704-
Application.put_env(:guarded_struct, :validate_derive, nil)
705-
Application.put_env(:guarded_struct, :sanitize_derive, nil)
704+
Application.put_env(:guarded_struct, :validate_derive, [TestValidate, TestValidate2])
705+
Application.put_env(:guarded_struct, :sanitize_derive, [TestSanitize, TestSanitize2])
706706

707707
defmodule TestCustomListDerive do
708708
use GuardedStruct
709709

710-
guardedstruct validate_derive: [TestValidate, TestValidate2],
711-
sanitize_derive: [TestSanitize, TestSanitize2] do
710+
guardedstruct do
712711
field(:id, integer())
713712
field(:title, String.t(), derive: "validate(not_empty, testv2)")
714713

0 commit comments

Comments
 (0)