Class: Filterameter::FilterRegistry
- Inherits:
-
Object
- Object
- Filterameter::FilterRegistry
- Defined in:
- lib/filterameter/filter_registry.rb
Overview
Filters
Class FilterRegistry is a collection of the filters. It captures the filter declarations when classes are loaded, then uses the injected FilterFactory to build the filters on demand as they are needed.
Instance Attribute Summary collapse
-
#ranges ⇒ Object
readonly
Returns the value of attribute ranges.
Instance Method Summary collapse
- #add_filter(parameter_name, options) ⇒ Object
- #fetch(name) ⇒ Object
- #filter_declarations ⇒ Object
-
#initialize(filter_factory) ⇒ FilterRegistry
constructor
A new instance of FilterRegistry.
Constructor Details
#initialize(filter_factory) ⇒ FilterRegistry
Returns a new instance of FilterRegistry.
11 12 13 14 15 16 |
# File 'lib/filterameter/filter_registry.rb', line 11 def initialize(filter_factory) @filter_factory = filter_factory @declarations = {} @ranges = {} @filters = {} end |
Instance Attribute Details
#ranges ⇒ Object (readonly)
Returns the value of attribute ranges.
9 10 11 |
# File 'lib/filterameter/filter_registry.rb', line 9 def ranges @ranges end |
Instance Method Details
#add_filter(parameter_name, options) ⇒ Object
18 19 20 21 22 |
# File 'lib/filterameter/filter_registry.rb', line 18 def add_filter(parameter_name, ) @declarations[parameter_name.to_s] = Filterameter::FilterDeclaration.new(parameter_name, ).tap do |fd| add_declarations_for_range(fd, , parameter_name) if fd.range_enabled? end end |
#fetch(name) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/filterameter/filter_registry.rb', line 24 def fetch(name) name = name.to_s @filters.fetch(name) do raise Filterameter::Exceptions::UndeclaredParameterError, name unless @declarations.keys.include?(name) @filters[name] = @filter_factory.build(@declarations[name]) end end |
#filter_declarations ⇒ Object
33 34 35 |
# File 'lib/filterameter/filter_registry.rb', line 33 def filter_declarations @declarations.values end |