Resourceful.Collection (Resourceful v0.1.6)

View Source

Provides a common interface for querying and retrieving collections.

Deligated modules designed to interact directly with the underlying data or data sources must return alls of resources. For instance, when using Ecto, this module should return alls of structs or maps and not queries that have not been executed yet.

Data Sources

A data_source can be another from an Ecto schema, to a module that intteracts with a remote API, to a list as long as there is an underlying module to support the common interfaces. (For now, that's just Ecto.)

Summary

Types

name()

@type name() :: atom() | String.t()

page_info()

@type page_info() :: %{
  number: integer(),
  resources: integer(),
  size: integer(),
  total: integer()
}

queryable()

@type queryable() :: name() | {name(), name()} | Resourceful.Type.queryable()

with_page_info()

@type with_page_info() :: {[any()], page_info()}

with_page_info(type)

@type with_page_info(type) :: {[type], page_info()}

Functions

all(data_source, opts \\ [])

@spec all(
  any(),
  keyword()
) :: [any()]

Returns a list of resources that may be filtered and sorted depending on on options. Resources will always be paginated.

Args:

  • data_source: See module overview.
  • opts: Keyword list of options

Options:

Additionally, see settings for the delegated module as it may take additional options.

all_with_page_info(data_source, opts \\ [])

@spec all_with_page_info(
  any(),
  keyword()
) :: with_page_info()

any?(data_source, opts \\ [])

@spec any?(
  any(),
  keyword()
) :: boolean()

Checks if data_source contains any resources.

Args:

  • data_source: See module overview.
  • opts: Keyword list of options

Options: See settings for the delegated module (e.g. Resourceful.Collection.Ecto).

default_page_size()

@spec default_page_size() :: integer()

filter(data_source, filters, opts \\ [])

@spec filter(any(), keyword(), keyword()) :: any()

page_info(data_source, opts)

@spec page_info(
  any(),
  keyword()
) :: page_info()

Returns the total number of resources and pages based on page_size in a data_source.

Args:

  • data_source: See module overview.
  • opts: Keyword list of options

Options: See settings for the delegated module (e.g. Resourceful.Collection.Ecto).

page_info(data_source, page_size, opts \\ [])

@spec page_info(any(), integer(), keyword()) :: page_info()

page_number_or_default(opts)

@spec page_number_or_default(keyword()) :: integer()

page_size_or_default(opts)

@spec page_size_or_default(keyword()) :: integer()

paginate(data_source, opts \\ [])

@spec paginate(
  any(),
  keyword()
) :: [any()]

paginate(data_source, number, size, opts \\ [])

@spec paginate(any(), integer(), integer(), keyword()) :: [any()]

paginate_with_info(data_source, opts \\ [])

@spec paginate_with_info(
  any(),
  keyword()
) :: with_page_info()

query(data_source, opts)

@spec query(
  any(),
  keyword()
) :: any()

sort(data_source, sorters, opts \\ [])

@spec sort(any(), keyword(), keyword()) :: any()

total(data_source, opts \\ [])

@spec total(
  any(),
  keyword()
) :: integer()

Returns the total number of resources in a data_source.

Args:

  • data_source: See module overview.
  • opts: Keyword list of options

Options: See settings for the delegated module (e.g. Resourceful.Collection.Ecto).