Class: Stockboy::FilterChain
- Inherits:
-
Hash
- Object
- Hash
- Stockboy::FilterChain
- Defined in:
- lib/stockboy/filter_chain.rb
Overview
A hash for executing items in order with callbacks
Class Method Summary collapse
-
.new(hash = nil) ⇒ Object
Initialize a new FilterChain with a hash of filters.
Instance Method Summary collapse
-
#keys_to_arrays ⇒ Hash{Symbol=>Array}
Filter keys point to empty arrays.
-
#prepend(hash) ⇒ Object
Add filters to the front of the chain.
-
#reset ⇒ Hash{Symbol=>Array}
Call the reset callback on all filters that respond to it.
Class Method Details
.new(hash = nil) ⇒ Object
Initialize a new FilterChain with a hash of filters
11 12 13 |
# File 'lib/stockboy/filter_chain.rb', line 11 def self.new(hash=nil) super().replace(hash || {}) end |
Instance Method Details
#keys_to_arrays ⇒ Hash{Symbol=>Array}
Returns Filter keys point to empty arrays.
36 37 38 |
# File 'lib/stockboy/filter_chain.rb', line 36 def keys_to_arrays Hash[keys.map { |k| [k, []] }] end |
#prepend(hash) ⇒ Object
Add filters to the front of the chain
19 20 21 |
# File 'lib/stockboy/filter_chain.rb', line 19 def prepend(hash) replace hash.merge(self) end |
#reset ⇒ Hash{Symbol=>Array}
Call the reset callback on all filters that respond to it
27 28 29 30 31 32 |
# File 'lib/stockboy/filter_chain.rb', line 27 def reset each do |key, filter| filter.reset if filter.respond_to? :reset end keys_to_arrays end |