View Source Spark.OptionsHelpers (spark v1.1.53)

Helpers for working with our superset of nimble options.

Additional Types

Spark provides the following additional option types for use when building DSLs or validating options.

  • {:one_of, values} - maps to {:in, values} for backwards compatibility
  • {:tagged_tuple, tag, inner_type} - maps to {tag, type}
  • {:spark_behaviour, behaviour} - expects a module that implements the given behaviour, and can be specified with options, i.e mod or {mod, [opt: :val]}
  • {:spark_behaviour, behaviour, builtin_module} - Same as the above, but also accepts a builtin_module. The builtin_module is used to provide additional options for the elixir_sense plugin.
  • {:spark_function_behaviour, behaviour, {function_mod, arity}} - expects a module that implements the given behaviour, and can be specified with options, i.e mod or {mod, [opt: :val]}, that also has a special module that supports being provided an anonymous function or MFA as the :fun option.
  • {:spark_function_behaviour, behaviour, builtin_module, {function_mod, arity}} - Same as the above, but also accepts a builtin_module. The builtin_module is used to provide additional options for the elixir_sense plugin.
  • {:behaviour, behaviour} - expects a module that implements a given behaviour.
  • {:spark, dsl_module} - expects a module that is a Spark.Dsl
  • {:mfa_or_fun, arity} - expects a function or MFA of a corresponding arity.
  • {:spark_type, module, builtin_function} - a behaviour that defines builtin_function/0 that returns a list of atoms that map to built in variations of that thing.
  • {:spark_type, module, builtin_function, templates} - same as the above, but includes additional templates for elixir_sense autocomplete
  • :fun - a function of any arity
  • :literal -> any literal value. Maps to :any, but is used for documentation.
  • {:literal, value} -> exactly the value specified.
  • :quoted -> retains the quoted value of the code provided to the option
  • {:wrap_list, type} -> Allows a single value or a list of values.

Summary

Types

The schema type, as defined by the NimbleOptions docs.

The types as specified by the NimbleOptions docs.

The actual schema type, as used in sections and entities.

Spark provides additional types on top of those provided by NimbleOptions.

Types

@type nimble_schema() :: [
  type: type() | :any,
  required: boolean(),
  default: :any,
  keys: Keyword.t({:type, type()}),
  deprecated: String.t(),
  doc: String.t(),
  subsection: String.t(),
  type_doc: false | String.t(),
  rename_to: atom()
]

The schema type, as defined by the NimbleOptions docs.

@type nimble_types() ::
  :any
  | :keyword_list
  | :non_empty_keyword_list
  | :map
  | {:map, key_type :: type(), value_type :: type()}
  | :atom
  | :string
  | :boolean
  | :integer
  | :non_neg_integer
  | :pos_integer
  | :float
  | :timeout
  | :pid
  | :reference
  | :mfa
  | :mod_arg
  | {:fun, arity :: non_neg_integer()}
  | {:in, [type()] | Range.t()}
  | {:custom, module(), function :: atom(), args :: [any()]}
  | {:or, [type()]}
  | {:list,
     type() | {:keyword_list, type()} | {:non_empty_keyword_list, type()}}
  | {:tuple,
     [type() | {:keyword_list, type()} | {:non_empty_keyword_list, type()}]}

The types as specified by the NimbleOptions docs.

@type schema() :: Keyword.t(nimble_schema())

The actual schema type, as used in sections and entities.

@type type() ::
  nimble_types()
  | {:one_of, [type()]}
  | {:tagged_tuple, tag :: type(), inner_type :: type()}
  | {:spark_behaviour, module()}
  | {:spark_behaviour, module(), module()}
  | {:spark_function_behaviour, module(), {module(), integer()}}
  | {:spark_function_behaviour, module(), module(), {module(), integer()}}
  | {:behaviour, module()}
  | {:spark, module()}
  | {:mfa_or_fun, non_neg_integer()}
  | {:spark_type, module(), builtin_function :: atom()}
  | {:spark_type, module(), builtin_function :: atom(),
     templates :: [String.t()]}
  | {:struct, module()}
  | :fun
  | {:fun, [type()]}
  | {:fun, [type()], type()}
  | {:wrap_list, type()}
  | :literal
  | {:literal, any()}
  | :quoted

Spark provides additional types on top of those provided by NimbleOptions.

Functions

Link to this function

append_doc!(options, field, to_append)

View Source

Creates markdown documentation for a given schema.

This function is deprecated. Use {:list, :atom} instead.
Link to this function

literal_value(value, value)

View Source
Link to this function

make_optional!(options, field)

View Source
Link to this function

make_required!(options, field)

View Source
Link to this function

merge_schemas(left, right, section \\ nil)

View Source

Merges two schemas, and sets the subsection option on all options on the right side.

Link to this function

mfa_or_fun(value, arity)

View Source
Link to this function

set_default!(options, field, value)

View Source
Link to this function

set_type!(options, field, type)

View Source
Link to this function

spark_behaviour(module, behaviour)

View Source
Link to this function

spark_function_behaviour(module, behaviour, arg3)

View Source
Link to this function

tagged_tuple(other, key, type, tag)

View Source

Sanitizes the option schema and validates with NimbleOptions.

Sanitizes the option schema and validates with NimbleOptions.

Link to this function

wrap_list(value, key, type)

View Source