Macaw.Data.Derived.Context (macaw_data v0.5.3)

Copy Markdown View Source

The context a derived source's function of two arguments is called with (spec/02 §2.3): each input's schema as data and its delivery's served facts. It holds no clock and no variables: a variable is an input like any other.

Every name is a string: a field's, a description's key, a value entry's key. A value is the term the schema or the delivery holds, read through value: a stored function's by the rule its literals follow (a word's atom, else the string), a host's as given.

iex> alias Macaw.Data.{Delivery, Schema}
iex> schema = Schema.new!(%{cpu: %{type: :number, bounds: [0, 100]}})
iex> delivery = Delivery.new([%{cpu: 3}], served: [window: [0, 10], capped: true])
iex> Macaw.Data.Derived.Context.new([%{key: "hosts", delivery: delivery, schema: schema}])
%{"inputs" => %{"hosts" => %{"schema" => %{"cpu" => %{"bounds" => [0, 100], "type" => :number}},
  "window" => [0, 10], "resolution" => nil, "capped" => true}}}

Ported from visualize's Visualize.VirtualSource.Context, its "vars" left out (spec/02 §2.3).

Summary

Types

An input as the owner gathered it: its key, its delivery and its schema.

Functions

The context of the inputs: key gives an input's key as the first argument keys it (its string by default), value a value as the function reads it (as given by default).

A schema as data, as a term: each field's name its string, each description's keys their strings, a value entry a map of its keys' strings, and every value read through value.

Types

input()

@type input() :: %{
  key: term(),
  delivery: Macaw.Data.Delivery.t(),
  schema: Macaw.Data.Schema.t()
}

An input as the owner gathered it: its key, its delivery and its schema.

Functions

new(inputs, key \\ &to_string/1, value \\ & &1)

@spec new([input()], (term() -> term()), (term() -> term())) :: map()

The context of the inputs: key gives an input's key as the first argument keys it (its string by default), value a value as the function reads it (as given by default).

schema(schema, value \\ & &1)

@spec schema(Macaw.Data.Schema.t(), (term() -> term())) :: map()

A schema as data, as a term: each field's name its string, each description's keys their strings, a value entry a map of its keys' strings, and every value read through value.