Cinder.Filters.Registry (Cinder v0.5.0)
View SourceRegistry for managing available filter types in Cinder.
Provides centralized registration and discovery of filter implementations, along with default filter type inference based on data types.
Summary
Functions
Returns a map of all registered filter types to their implementing modules.
Gets all filters including custom registered ones.
Checks if a filter type is a custom (user-registered) filter.
Gets default filter options for a given filter type.
Returns a list of all registered filter type atoms.
Gets the implementing module for a filter type.
Infers the appropriate filter type based on Ash resource attribute.
Lists all registered custom filter types.
Registers custom filters from application configuration.
Checks if a filter type is registered.
Validates that all registered custom filters are properly implemented.
Functions
Returns a map of all registered filter types to their implementing modules.
Gets all filters including custom registered ones.
Custom filters take precedence over built-in filters if there's a naming conflict (though registration prevents this from happening).
Returns
Map of all filter types to their implementing modules
Examples
iex> Cinder.Filters.Registry.all_filters_with_custom()
%{
text: Cinder.Filters.Text,
select: Cinder.Filters.Select,
slider: MyApp.Filters.Slider
}
Checks if a filter type is a custom (user-registered) filter.
Parameters
filter_type
- Filter type atom to check
Returns
Boolean indicating if the filter type is custom
Examples
iex> Cinder.Filters.Registry.custom_filter?(:slider)
true
iex> Cinder.Filters.Registry.custom_filter?(:text)
false
Gets default filter options for a given filter type.
Parameters
filter_type
- Filter type atomcolumn_key
- Column key for context (optional)
Returns
Keyword list of default options for the filter type
Returns a list of all registered filter type atoms.
Examples
iex> Cinder.Filters.Registry.filter_types()
[:text, :select, :multi_select, :multi_checkboxes, :date_range, :number_range, :boolean]
Gets the implementing module for a filter type.
Checks both built-in and custom registered filters.
Examples
iex> Cinder.Filters.Registry.get_filter(:text)
Cinder.Filters.Text
iex> Cinder.Filters.Registry.get_filter(:slider)
MyApp.Filters.Slider
iex> Cinder.Filters.Registry.get_filter(:unknown)
nil
Infers the appropriate filter type based on Ash resource attribute.
Parameters
attribute
- Ash resource attribute definitioncolumn_key
- Column key for context
Returns
Atom representing the inferred filter type
Lists all registered custom filter types.
Returns
Map of custom filter types to their implementing modules
Examples
iex> Cinder.Filters.Registry.list_custom_filters()
%{slider: MyApp.Filters.Slider, color_picker: MyApp.Filters.ColorPicker}
Registers custom filters from application configuration.
This function should be called during application startup to register filters defined in config files.
Configuration
config :cinder, :filters, %{
slider: MyApp.Filters.Slider,
color_picker: MyApp.Filters.ColorPicker
}
Returns
:ok if all filters registered successfully, {:error, [reasons]} if any failed
Checks if a filter type is registered.
Checks both built-in and custom registered filters.
Examples
iex> Cinder.Filters.Registry.registered?(:text)
true
iex> Cinder.Filters.Registry.registered?(:slider)
true
iex> Cinder.Filters.Registry.registered?(:unknown)
false
Validates that all registered custom filters are properly implemented.
This function can be called at application startup to ensure all custom filters are valid and will work correctly.
Returns
:ok if all filters are valid, {:error, [reasons]} if any are invalid
Examples
iex> Cinder.Filters.Registry.validate_custom_filters()
:ok
iex> Cinder.Filters.Registry.validate_custom_filters()
{:error, ["Module MyApp.Filters.BrokenSlider does not implement required function render/4"]}