Sphynx.Riddle behaviour (Sphynx v0.1.0) View Source

Main module for making riddles

Link to this section Summary

Types

A custom module of user which implement Sphynx.Riddle

Callbacks

Returns answer for riddle. Will be called when user gonna try to check his answer.

Checking answer for current riddle

Returns context for riddle. This function will be called when you try to create riddle.

Returns init args

Pre-action of making a riddle. As example, it can be email or SMS sending.

Handles result of checking answer to riddle

Functions

Function for putting custom context data

Function for putting user options

Link to this section Types

Specs

user_module() :: %{options: Keyword.t(), register: List.t(), context: Any.t()}

A custom module of user which implement Sphynx.Riddle

Link to this section Callbacks

Specs

answer(user_module()) :: Any.t()

Returns answer for riddle. Will be called when user gonna try to check his answer.

Link to this callback

check(user_module, t, t)

View Source

Specs

check(user_module(), Any.t(), Any.t()) :: Boolean.t()

Checking answer for current riddle

Args:

  • riddle - user module, Sphynx.Riddle implementation
  • actual_answer - answer, returned by user module or actual in struct
  • answer - the received answer that we have to check
Link to this callback

context(user_module)

View Source (optional)

Specs

context(user_module()) :: Any.t()

Returns context for riddle. This function will be called when you try to create riddle.

Function passes context data and return context data.

Specs

init(Keyword.t()) :: Keyword.t()

Returns init args

Specs

make(user_module()) :: user_module()

Pre-action of making a riddle. As example, it can be email or SMS sending.

Args

Returns self

Specs

verdict(user_module(), Any.t()) :: Any.t()

Handles result of checking answer to riddle

Args:

  • riddle - user module, Sphynx.Riddle implementation
  • result - result of calling check/3 function

Returns:

  • if result is {:proceed, user_module()} - gonna ge started new riddle
  • if result is {:break, _} - clash gonna be stopped
  • if result has another data - this another data will be returned

Link to this section Functions

Link to this function

put_context(user_module, context)

View Source

Specs

put_context(user_module(), Any.t()) :: user_module()

Function for putting custom context data

Link to this function

put_options(user_module, options)

View Source

Specs

put_options(user_module(), Map.t()) :: user_module()

Function for putting user options