class Stockboy::FilterChain

A hash for executing items in order with callbacks

Public Class Methods

new(hash=nil) click to toggle source

Initialize a new FilterChain with a hash of filters

@param [Hash{Symbol=>Filter}] hash

Calls superclass method
# File lib/stockboy/filter_chain.rb, line 11
def self.new(hash=nil)
  super().replace(hash || {})
end

Public Instance Methods

keys_to_arrays() click to toggle source

@return [Hash{Symbol=>Array}] Filter keys point to empty arrays

# File lib/stockboy/filter_chain.rb, line 36
def keys_to_arrays
  Hash[keys.map { |k| [k, []] }]
end
prepend(hash) click to toggle source

Add filters to the front of the chain

@param [Hash{Symbol=>Filter}] hash Filters to add

# File lib/stockboy/filter_chain.rb, line 19
def prepend(hash)
  replace hash.merge(self)
end
reset() click to toggle source

Call the reset callback on all filters that respond to it

@return [Hash{Symbol=>Array}] Filter keys point to empty arrays

# 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