Class: Attr::Gather::Aggregators::Base Abstract
- Inherits:
-
Object
- Object
- Attr::Gather::Aggregators::Base
- Defined in:
- lib/attr/gather/aggregators/base.rb
Overview
This class is abstract.
Subclass and override #call to implement a custom Aggregator class.
Direct Known Subclasses
Constant Summary collapse
Instance Attribute Summary collapse
-
#filter ⇒ Attr::Gather::Filters::Base
Filter for the output data.
Instance Method Summary collapse
- #call(_original_input, _results_array) ⇒ Object
-
#initialize(**opts) ⇒ Base
constructor
A new instance of Base.
- #with(**opts) ⇒ Object
Constructor Details
#initialize(**opts) ⇒ Base
Returns a new instance of Base.
18 19 20 |
# File 'lib/attr/gather/aggregators/base.rb', line 18 def initialize(**opts) @filter = opts.delete(:filter) || NOOP_FILTER end |
Instance Attribute Details
#filter ⇒ Attr::Gather::Filters::Base
Returns filter for the output data.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/attr/gather/aggregators/base.rb', line 13 class Base attr_accessor :filter NOOP_FILTER = Filters::Noop.new def initialize(**opts) @filter = opts.delete(:filter) || NOOP_FILTER end def with(**opts) self.class.new(filter: @filter, **opts) end def call(_original_input, _results_array) raise NotImplementedError end private def unwrap_result(res) return res if filter.nil? filter.call(res).value end end |
Instance Method Details
#call(_original_input, _results_array) ⇒ Object
26 27 28 |
# File 'lib/attr/gather/aggregators/base.rb', line 26 def call(_original_input, _results_array) raise NotImplementedError end |
#with(**opts) ⇒ Object
22 23 24 |
# File 'lib/attr/gather/aggregators/base.rb', line 22 def with(**opts) self.class.new(filter: @filter, **opts) end |