Class: Filterameter::Registries::Registry
- Inherits:
-
Object
- Object
- Filterameter::Registries::Registry
- Defined in:
- lib/filterameter/registries/registry.rb
Overview
# Registry
Class Registry records declarations and allows resulting filters and sorts to be fetched from sub-registries.
Instance Method Summary collapse
- #add_filter(parameter_name, options) ⇒ Object
- #add_sort(parameter_name, options) ⇒ Object
- #fetch_filter(parameter_name) ⇒ Object
- #fetch_sort(parameter_name) ⇒ Object
-
#initialize(model_class) ⇒ Registry
constructor
A new instance of Registry.
Constructor Details
#initialize(model_class) ⇒ Registry
Returns a new instance of Registry.
13 14 15 16 |
# File 'lib/filterameter/registries/registry.rb', line 13 def initialize(model_class) @filter_registry = Filterameter::Registries::FilterRegistry.new(Filterameter::FilterFactory.new(model_class)) @sort_registry = Filterameter::Registries::SortRegistry.new(Filterameter::SortFactory.new(model_class)) end |
Instance Method Details
#add_filter(parameter_name, options) ⇒ Object
18 19 20 21 |
# File 'lib/filterameter/registries/registry.rb', line 18 def add_filter(parameter_name, ) declaration = @filter_registry.add(parameter_name, ) add_sort(parameter_name, .slice(:name, :association)) if declaration.sortable? end |
#add_sort(parameter_name, options) ⇒ Object
27 28 29 |
# File 'lib/filterameter/registries/registry.rb', line 27 def add_sort(parameter_name, ) @sort_registry.add(parameter_name, ) end |
#fetch_filter(parameter_name) ⇒ Object
23 24 25 |
# File 'lib/filterameter/registries/registry.rb', line 23 def fetch_filter(parameter_name) @filter_registry.fetch(parameter_name) end |
#fetch_sort(parameter_name) ⇒ Object
31 32 33 |
# File 'lib/filterameter/registries/registry.rb', line 31 def fetch_sort(parameter_name) @sort_registry.fetch(parameter_name) end |