Sha256: a7eeda2c18a52b6e91fa3ec0e0561c496a60de17fbf313fdd607efaeda26b0fa

Contents?: true

Size: 1.2 KB

Versions: 3

Compression:

Stored size: 1.2 KB

Contents

class Kicker
  class CallbackChain < Array
    alias_method :append_callback,  :push
    alias_method :prepend_callback, :unshift
    
    def call(kicker, files)
      each do |callback|
        break if files.empty?
        callback.call(kicker, files)
      end
    end
  end
  
  class << self
    def pre_process_chain
      @pre_process_chain ||= CallbackChain.new
    end
    
    def process_chain
      @process_chain ||= CallbackChain.new
    end
    
    def post_process_chain
      @post_process_chain ||= CallbackChain.new
    end
    
    def full_chain
      @full_chain ||= CallbackChain.new([pre_process_chain, process_chain, post_process_chain])
    end
    
    def pre_process_callback=(callback)
      pre_process_chain.append_callback(callback)
    end
    
    def process_callback=(callback)
      process_chain.append_callback(callback)
    end
    
    def post_process_callback=(callback)
      post_process_chain.prepend_callback(callback)
    end
  end
  
  def pre_process_chain
    self.class.pre_process_chain
  end
  
  def process_chain
    self.class.process_chain
  end
  
  def post_process_chain
    self.class.post_process_chain
  end
  
  def full_chain
    self.class.full_chain
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
alloy-kicker-1.9.1 lib/kicker/callback_chain.rb
alloy-kicker-1.9.2 lib/kicker/callback_chain.rb
alloy-kicker-1.9.3 lib/kicker/callback_chain.rb