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(parameter_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 23 |
# File 'lib/filterameter/filter_registry.rb', line 18 def add_filter(parameter_name, ) name = parameter_name.to_s @declarations[name] = Filterameter::FilterDeclaration.new(name, ).tap do |fd| add_declarations_for_range(fd, , name) if fd.range_enabled? end end |
#fetch(parameter_name) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/filterameter/filter_registry.rb', line 25 def fetch(parameter_name) name = parameter_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
34 35 36 |
# File 'lib/filterameter/filter_registry.rb', line 34 def filter_declarations @declarations.values end |