Arke.StructManager (Arke v0.9.0-rc.0)

Copy Markdown View Source

Module that provides function for getting Arke and Unit structs. It also provides functions for encoding and decoding Units.

Summary

Functions

Function that decodes data into a Unit or list of Unit

Function that encodes a Unit or list of Unit

Function that returns a Struct that describes an Arke or a Unit

Types

parameter()

@type parameter() :: %{
  default: String.t() | boolean() | atom() | map() | list() | nil,
  helper_text: String.t() | nil,
  id: String.t(),
  label: String.t(),
  required: boolean() | nil,
  type: String.t(),
  key: String.t() | boolean() | atom() | map() | list() | nil
}

Functions

decode(project, arke_id, json, arg4)

@spec decode(
  project :: atom(),
  arke_id :: atom(),
  json :: %{key: String.t() | number() | boolean() | atom()},
  format :: atom()
) :: Arke.Core.Unit.t()

Function that decodes data into a Unit or list of Unit

Parameters

  • project => :atom => identify the Arke.Core.Project
  • arke_id => atom | string => arke id

  • json => %{key: value} => json data that we want to decode
  • type => :json => data input type

Example

iex> StructManager.decode(:arke, my_json_data, :json)

encode(unit, opts \\ [])

@spec encode(unit :: Arke.Core.Unit.t(), format :: atom()) :: %{
  key: String.t() | number() | boolean() | atom()
}

Function that encodes a Unit or list of Unit

Parameters

  • unit => [%{arke_struct}] | %{arke_struct} => unit or list of units that we want to encode

  • type => :json => desired encode type

Example

iex> units = QueryManager.filter_by(arke_id: id)
...> StructManager.encode(units, type: :json)

get_struct(arke)

@spec get_struct(arke :: Arke.Core.Unit.t()) :: %{
  parameters: [parameter()],
  label: String.t()
}

Function that returns a Struct that describes an Arke or a Unit

Parameters

  • unit => %Unit{} | %Arke{} => unit or arke struct

Example

  iex> arke = ArkeManager.get(:test, :default)
  ...> StructManager.get_struct(arke)

get_struct(arke, unit)

@spec get_struct(arke :: Arke.Core.Unit.t(), opts :: list()) :: %{
  parameters: [parameter()],
  label: String.t()
}

get_struct(arke, unit, opts)

validate_data(id, value, arke, opts \\ [])