Sha256: 308b96e5d17c6ef073209b83961ace1925af283646591483353b6acb2b2faaab

Contents?: true

Size: 847 Bytes

Versions: 7

Compression:

Stored size: 847 Bytes

Contents

module Daemonizer
  class Handler
    attr_accessor :worker_id
    attr_accessor :workers_count
    attr_accessor :logger
    
    def initialize(handler_options = {})
      @handler_options = handler_options
    end
    
    def prepare(starter, &block)
      if block_given?
        yield
      end
      starter.call
    end
    
    def option(key)
      if handler_option = @handler_options[key.to_sym]
        handler_option.value(self)
      else
        nil
      end
    end
  end
  
  class FakeHandler < Handler
    def initialize(prepare, start, handler_options = {})
      @prepare = prepare
      @start = start
      super(handler_options)
    end
    
    def prepare(starter, &block)
      @prepare.call(block) if @prepare
      super
    end
        
    def start
      @start.call(@worker_id, @workers_count)
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
daemonizer-0.5.0.beta.1 lib/daemonizer/handler.rb
daemonizer-0.4.18 lib/daemonizer/handler.rb
daemonizer-0.4.17 lib/daemonizer/handler.rb
daemonizer-0.4.16 lib/daemonizer/handler.rb
daemonizer-0.4.15 lib/daemonizer/handler.rb
daemonizer-0.4.14 lib/daemonizer/handler.rb
daemonizer-0.4.13 lib/daemonizer/handler.rb