View Source Estructura.Aston (estructura v1.6.0)

The implementation of Estructura ready to work with tree AST-like structure

Summary

Functions

Returns the generator to be used in StreamData-powered property testing, based on the specification given to use Estructura, which contained

Returns the key to be used for accessing the nested element(s)

Coerces the deeply nested map to an instance of nested Estructura.Aston

Gets the value for the given key from the structure

Puts the value for the given key into the structure, passing coercion and validation, returns {:ok, updated_struct} or {:error, reason} if there is no such key

Puts the value for the given key into the structure, passing coercion and validation, returns the value or raises if there is no such key

Converts Estructura.Aston to the XML AST understandable by XmlBuilder

Types

t()

@type t() :: %Estructura.Aston{
  name: atom() | binary(),
  attributes: map(),
  content: nil | binary() | [binary() | t()]
}

Functions

__generator__()

@spec __generator__() ::
  StreamData.t(%Estructura.Aston{
    attributes: term(),
    content: term(),
    name: term()
  })

See Estructura.Aston.__generator__/1

__generator__(this)

@spec __generator__(%Estructura.Aston{
  attributes: term(),
  content: term(),
  name: term()
}) ::
  StreamData.t(%Estructura.Aston{
    attributes: term(),
    content: term(),
    name: term()
  })

Returns the generator to be used in StreamData-powered property testing, based on the specification given to use Estructura, which contained

shape

%Estructura.Config{
  access: true,
  coercion: true,
  validation: true,
  calculated: [],
  collectable: :content,
  enumerable: true,
  generator: [
    name: {StreamData, :string, [:alphanumeric]},
    attributes: {StreamData, :map_of,
     [
       {StreamData, :atom, [:alphanumeric]},
       {StreamData, :one_of,
        [
          [
            {StreamData, :integer},
            {StreamData, :boolean},
            {StreamData, :string, [:alphanumeric]}
          ]
        ]}
     ]},
    content: {StreamData, :tree,
     [{StreamData, :fixed_list, [[]]}, &Estructura.Aston.child_gen/1]}
  ]
}

The argument given would be used as a template to generate new values.

access(aston, path)

Returns the key to be used for accessing the nested element(s)

coerce(term, opts \\ [], root \\ nil)

@spec coerce(any(), keyword(), nil | any()) :: {:ok, value} | {:error, reason}
when value: any(), reason: String.t()

Coerces the deeply nested map to an instance of nested Estructura.Aston

get(data, key, default \\ nil)

@spec get(
  %Estructura.Aston{attributes: term(), content: term(), name: term()},
  Estructura.Config.key(),
  any()
) :: any()

Gets the value for the given key from the structure

put(data, key, value)

@spec put(
  %Estructura.Aston{attributes: term(), content: term(), name: term()},
  Estructura.Config.key(),
  any()
) ::
  {:ok, %Estructura.Aston{attributes: term(), content: term(), name: term()}}
  | {:error, any()}

Puts the value for the given key into the structure, passing coercion and validation, returns {:ok, updated_struct} or {:error, reason} if there is no such key

put!(data, key, value)

@spec put!(
  %Estructura.Aston{attributes: term(), content: term(), name: term()},
  Estructura.Config.key(),
  any()
) ::
  %Estructura.Aston{attributes: term(), content: term(), name: term()}
  | no_return()

Puts the value for the given key into the structure, passing coercion and validation, returns the value or raises if there is no such key

recalculate_calculated(data)

to_ast(tree)

@spec to_ast(t()) :: {element, map(), content}
when element: atom() | binary(), content: nil | binary() | list()

Converts Estructura.Aston to the XML AST understandable by XmlBuilder