View Source Estructura.Aston (estructura v1.4.1)

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

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

Functions

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

See Estructura.Aston.__generator__/1

@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.

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

Link to this function

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

View Source
@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

Link to this function

get(data, key, default \\ nil)

View Source
@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

@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

@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

Link to this function

recalculate_calculated(data)

View Source
@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