Sha256: 9e35b2678b5efef32abab5c1a192106f497fbe1b2d7a6394380ebee7a07ec01e

Contents?: true

Size: 864 Bytes

Versions: 4

Compression:

Stored size: 864 Bytes

Contents

module Daemonizer
  class Handler
    attr_accessor :worker_id
    attr_accessor :workers_count
    attr_accessor :logger
    
    def initialize(options = {})
      @options = options
    end
    
    def before_init(block)
      block.call
    end
    
    def option(key)
      if option = @options[key.to_sym] and option.is_a?(Proc)
        option.call(@worker_id, @workers_count)
      else
        option
      end
    end
  end
  
  class FakeHandler < Handler
    def initialize(before_init, after_init, options = {})
      @before_init = before_init
      @after_init = after_init
      super(options)
    end
    
    def before_init(block)
      if @before_init
        @before_init.call(@logger, block)
      else
        super
      end
    end
        
    def after_init
      @after_init.call(@logger, @worker_id, @workers_count)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
daemonizer-0.1.0 lib/daemonizer/handler.rb
daemonizer-0.0.8 lib/daemonizer/handler.rb
daemonizer-0.0.7 lib/daemonizer/handler.rb
daemonizer-0.0.6 lib/daemonizer/handler.rb