Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function docs for pipeline module #658

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions lib/absinthe/pipeline.ex
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ defmodule Absinthe.Pipeline do

@doc """
Return the part of a pipeline before a specific phase.

## Examples

iex> Pipeline.before([A, B, C], B)
[A]
"""
@spec before(t, atom) :: t
def before(pipeline, phase) do
Expand All @@ -158,6 +163,11 @@ defmodule Absinthe.Pipeline do

@doc """
Return the part of a pipeline after (and including) a specific phase.

## Examples

iex> Pipeline.from([A, B, C], B)
[B, C]
"""
@spec from(t, atom) :: t
def from(pipeline, phase) do
Expand Down Expand Up @@ -229,6 +239,11 @@ defmodule Absinthe.Pipeline do

@doc """
Return the part of a pipeline up to and including a specific phase.

## Examples

iex> Pipeline.upto([A, B, C], B)
[A, B]
"""
@spec upto(t, atom) :: t
def upto(pipeline, phase) do
Expand All @@ -237,24 +252,74 @@ defmodule Absinthe.Pipeline do
beginning ++ [item]
end

@doc """
Return the pipeline with the supplied phase removed.

## Examples

iex> Pipeline.without([A, B, C], B)
[A, C]
"""
@spec without(t, Phase.t()) :: t
def without(pipeline, phase) do
pipeline
|> Enum.filter(&(not match_phase?(phase, &1)))
end

@doc """
Return the pipeline with the phase/list of phases inserted before
the supplied phase.

## Examples

Add one phase before another:

iex> Pipeline.insert_before([A, C, D], C, B)
[A, B, C, D]

Add list of phase before another:

iex> Pipeline.insert_before([A, D, E], D, [B, C])
[A, B, C, D, E]

"""
@spec insert_before(t, Phase.t(), phase_config_t | [phase_config_t]) :: t
def insert_before(pipeline, phase, additional) do
beginning = before(pipeline, phase)
beginning ++ List.wrap(additional) ++ (pipeline -- beginning)
end

@doc """
Return the pipeline with the phase/list of phases inserted after
the supplied phase.

## Examples

Add one phase after another:

iex> Pipeline.insert_after([A, C, D], A, B)
[A, B, C, D]

Add list of phases after another:

iex> Pipeline.insert_after([A, D, E], A, [B, C])
[A, B, C, D, E]

"""
@spec insert_after(t, Phase.t(), phase_config_t | [phase_config_t]) :: t
def insert_after(pipeline, phase, additional) do
beginning = upto(pipeline, phase)
beginning ++ List.wrap(additional) ++ (pipeline -- beginning)
end

@doc """
Return the pipeline with the phases matching the regex removed.

## Examples

iex> Pipeline.reject([A, B, C], ~r/A|B/)
[C]
"""
@spec reject(t, Regex.t() | (Module.t() -> boolean)) :: t
def reject(pipeline, %Regex{} = pattern) do
reject(pipeline, fn phase ->
Expand Down