Sha256: 095a24c78ac7a17e923d020ad5359177361396deb49396b49906319c94ef3f51

Contents?: true

Size: 878 Bytes

Versions: 6

Compression:

Stored size: 878 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)
      if @prepare
        @prepare.call(block)
      else
        super
      end
    end
        
    def start
      @start.call(@worker_id, @workers_count)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
daemonizer-0.4.12 lib/daemonizer/handler.rb
daemonizer-0.4.11 lib/daemonizer/handler.rb
daemonizer-0.4.10 lib/daemonizer/handler.rb
daemonizer-0.4.9 lib/daemonizer/handler.rb
daemonizer-0.4.8 lib/daemonizer/handler.rb
daemonizer-0.4.7 lib/daemonizer/handler.rb