Skip to content

Commit

Permalink
Rename Types.Schema->Map
Browse files Browse the repository at this point in the history
  • Loading branch information
solnic committed Oct 4, 2023
1 parent c528514 commit 033153b
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 16 deletions.
15 changes: 7 additions & 8 deletions lib/drops/contract.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ defmodule Drops.Contract do
quote do
use Drops.Validator

alias Drops.Types.Schema
alias Drops.Types.Schema.Key
alias Drops.Types

import Drops.Contract
import Drops.Contract.Runtime
Expand All @@ -18,15 +17,15 @@ defmodule Drops.Contract do
conform(data, schema())
end

def conform(data, %Schema{atomize: true} = schema) do
conform(Schema.atomize(data, schema.keys), schema.keys)
def conform(data, %Types.Map{atomize: true} = schema) do
conform(Types.Map.atomize(data, schema.keys), schema.keys)
end

def conform(data, %Schema{} = schema) do
def conform(data, %Types.Map{} = schema) do
conform(data, schema.keys)
end

def conform(data, %Schema{} = schema, path: root) do
def conform(data, %Types.Map{} = schema, path: root) do
case conform(data, schema) do
{:ok, value} ->
{:ok, {root, value}}
Expand Down Expand Up @@ -55,7 +54,7 @@ defmodule Drops.Contract do
end
end

def validate(value, %Schema{} = schema, path: path) do
def validate(value, %Types.Map{} = schema, path: path) do
case validate(value, schema.constraints, path: path) do
{:ok, {_, validated_value}} ->
conform(validated_value, schema, path: path)
Expand All @@ -65,7 +64,7 @@ defmodule Drops.Contract do
end
end

defp apply_predicates(value, {:and, [left, %Schema{} = schema]}, path: path) do
defp apply_predicates(value, {:and, [left, %Types.Map{} = schema]}, path: path) do
case apply_predicate(left, {:ok, {path, value}}) do
{:ok, _} ->
conform(value, schema, path: path)
Expand Down
6 changes: 3 additions & 3 deletions lib/drops/types.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ defmodule Drops.Types do
Sum,
List,
Cast,
Schema,
Schema.Key
Map,
Map.Key
}

def from_spec(%{} = spec, opts) do
Expand All @@ -16,7 +16,7 @@ defmodule Drops.Types do
%Key{path: [name], presence: presence, type: from_spec(type_spec, opts)}
end)

%Schema{
%Map{
primitive: :map,
constraints: infer_constraints({:type, {:map, []}}, opts),
atomize: atomize,
Expand Down
4 changes: 2 additions & 2 deletions lib/drops/types/schema.ex → lib/drops/types/map.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Drops.Types.Schema do
alias Drops.Types.Schema.Key
defmodule Drops.Types.Map do
alias Drops.Types.Map.Key

defstruct [:primitive, :constraints, :keys, :atomize]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule Drops.Types.Schema.Key do
defmodule Drops.Types.Map.Key do
alias __MODULE__

defstruct [:path, :presence, :type]
Expand Down
2 changes: 1 addition & 1 deletion lib/drops/validator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule Drops.Validator do
quote do
alias Drops.{Casters, Predicates}
alias Drops.Types
alias Drops.Types.Schema.Key
alias Drops.Types.Map.Key

def validate(value, %Types.Cast{} = type, path: path) do
%{input_type: input_type, output_type: output_type, opts: cast_opts} = type
Expand Down
2 changes: 1 addition & 1 deletion test/test_helper.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule Drops.ContractCase do
quote do
import Drops.ContractCase

alias Drops.Contract.Schema
alias Drops.Contract.Map
end
end

Expand Down

0 comments on commit 033153b

Please sign in to comment.