Current section
12 Versions
Jump to
Current section
12 Versions
Compare versions
4
files changed
+35
additions
-26
deletions
| @@ -1,25 +1,30 @@ | |
| 1 1 | # Used by "mix format" |
| 2 | + locals_without_parens = [ |
| 3 | + # Type |
| 4 | + deftype: 2, |
| 5 | + # Schema |
| 6 | + field!: 1, |
| 7 | + field!: 2, |
| 8 | + field!: 3, |
| 9 | + embeds_one!: 2, |
| 10 | + embeds_one!: 3, |
| 11 | + embeds_one!: 4, |
| 12 | + embeds_many!: 2, |
| 13 | + embeds_many!: 3, |
| 14 | + embeds_many!: 4, |
| 15 | + # Extensions (Spark) |
| 16 | + attribute: 1, |
| 17 | + attribute: 2, |
| 18 | + option: 1, |
| 19 | + option: 2 |
| 20 | + ] |
| 21 | + |
| 2 22 | [ |
| 3 23 | inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"], |
| 4 24 | import_deps: [:ecto], |
| 5 | - locals_without_parens: [ |
| 6 | - # Type |
| 7 | - deftype: 2, |
| 8 | - # Schema |
| 9 | - field!: 1, |
| 10 | - field!: 2, |
| 11 | - field!: 3, |
| 12 | - embeds_one!: 2, |
| 13 | - embeds_one!: 3, |
| 14 | - embeds_one!: 4, |
| 15 | - embeds_many!: 2, |
| 16 | - embeds_many!: 3, |
| 17 | - embeds_many!: 4, |
| 18 | - # Extensions (Spark) |
| 19 | - attribute: 1, |
| 20 | - attribute: 2, |
| 21 | - option: 1, |
| 22 | - option: 2 |
| 23 | - ], |
| 24 | - plugins: [Spark.Formatter] |
| 25 | + locals_without_parens: locals_without_parens, |
| 26 | + plugins: [Spark.Formatter], |
| 27 | + export: [ |
| 28 | + locals_without_parens: locals_without_parens |
| 29 | + ] |
| 25 30 | ] |
| @@ -1,6 +1,6 @@ | |
| 1 1 | {<<"links">>,[{<<"GitHub">>,<<"https://github.com/acalejos/flint">>}]}. |
| 2 2 | {<<"name">>,<<"flint">>}. |
| 3 | - {<<"version">>,<<"0.4.0">>}. |
| 3 | + {<<"version">>,<<"0.4.1">>}. |
| 4 4 | {<<"description">>, |
| 5 5 | <<"Declarative Ecto embedded schemas for data validation, coercion, and manipulation.">>}. |
| 6 6 | {<<"elixir">>,<<"~> 1.14">>}. |
| @@ -135,7 +135,7 @@ defmodule Flint.Schema do | |
| 135 135 | "Required option #{inspect(option_name)} on field #{inspect(name)} not found." |
| 136 136 | ) |
| 137 137 | |
| 138 | - if required && validator && not validator.(value), |
| 138 | + if not is_nil(value) && validator && not validator.(value), |
| 139 139 | do: |
| 140 140 | raise( |
| 141 141 | ArgumentError, |
| @@ -438,13 +438,16 @@ defmodule Flint.Schema do | |
| 438 438 | def __embeds_module__(env, module, opts, block) do |
| 439 439 | {pk, opts} = Keyword.pop(opts, :primary_key, false) |
| 440 440 | |
| 441 | + extensions = Module.get_attribute(env.module, :extensions, []) |
| 442 | + |
| 441 443 | block = |
| 442 444 | quote do |
| 443 | - use Flint, |
| 445 | + use Flint.Schema, |
| 444 446 | primary_key: unquote(Macro.escape(pk)), |
| 445 447 | schema: [ |
| 446 448 | unquote(block) |
| 447 | - ] |
| 449 | + ], |
| 450 | + extensions: unquote(extensions) |
| 448 451 | end |
| 449 452 | |
| 450 453 | Module.create(module, block, env) |
| @@ -582,6 +585,7 @@ defmodule Flint.Schema do | |
| 582 585 | Module.register_attribute(__CALLER__.module, :extension_attributes, accumulate: true) |
| 583 586 | Module.register_attribute(__CALLER__.module, :extension_options, accumulate: true) |
| 584 587 | Module.register_attribute(__CALLER__.module, :extra_options, accumulate: true) |
| 588 | + Module.put_attribute(__CALLER__.module, :extensions, extensions) |
| 585 589 | |
| 586 590 | attrs = |
| 587 591 | Enum.map(attributes, fn {_extension, field} = attr -> |
| @@ -609,7 +613,7 @@ defmodule Flint.Schema do | |
| 609 613 | def __schema__(:required), do: @required |> Enum.reverse() |
| 610 614 | def __schema__(:blocks), do: @blocks |> Enum.reverse() |
| 611 615 | # Extension-Related Reflections |
| 612 | - def __schema__(:extensions), do: unquote(extensions) |
| 616 | + def __schema__(:extensions), do: @extensions |
| 613 617 | def __schema__(:extra_options), do: @extra_options |> Enum.reverse() |
| 614 618 | |
| 615 619 | defdelegate changeset(schema, params \\ %{}, bindings \\ []), to: Flint.Changeset |
| @@ -5,7 +5,7 @@ defmodule Flint.MixProject do | |
| 5 5 | [ |
| 6 6 | app: :flint, |
| 7 7 | name: "Flint", |
| 8 | - version: "0.4.0", |
| 8 | + version: "0.4.1", |
| 9 9 | elixir: "~> 1.14", |
| 10 10 | start_permanent: Mix.env() == :prod, |
| 11 11 | deps: deps(), |