Dagger.Mod.Object (dagger v0.19.4)
View SourceDeclare a module as an object type.
Declare an object
Add use Dagger.Mod.Object to the Elixir module that want to be a
Dagger module and give a name through :name configuration:
defmodule Potato do
use Dagger.Mod.Object, name: "Potato"
# ...
endThe module also support documentation by using Elixir standard documentation,
@moduledoc.
Declare a function
The module provides a defn, a macro for declare a function.
Let's declare a new function named echo that accepts a name as a string
and return a container that echo a name in the module Potato from the previous
section:
defmodule Potato do
use Dagger.Mod.Object, name: "Potato"
defn echo(name: String.t()) :: Dagger.Container.t() do
dag()
|> Dagger.Client.container()
|> Dagger.Container.from("alpine")
|> Dagger.Container.with_exec(["echo", name])
end
endFrom the example above, the defn allows you to annotate a type to function
arguments and return type by using Elixir Typespec. The type will convert to
a Dagger type when registering a module.
The supported primitive types for now are:
integer()for a boolean type.boolean()for a boolean type.String.t()orbinary()for a string type.list(type)or[type]for a list type.type | nilfor optional type.- Any type that generated under
Daggernamespace (Dagger.Container.t(),Dagger.Directory.t(), etc.).
The function also support documentation by using Elixir standard documentation,
@doc.
Summary
Functions
Declare a function.
Declare a field.
Get function documentation.
Get module documentation.
Declare an object struct.
Types
@type function_def() :: {function_name(), keyword()}
@type function_name() :: atom()
Functions
Declare a function.
Declare a field.
@spec get_function_doc(module(), function_name()) :: String.t() | nil
Get function documentation.
Return doc string or nil if that function didn't have a documentation.
Get module documentation.
Returns module doc string or nil if the given module didn't have a documentation.
Declare an object struct.