Sha256: 90724e69cb2f81b309e53b5d56ff155aa9dc95daac1ba60d44e82e8a2c7e786b

Contents?: true

Size: 1.38 KB

Versions: 4

Compression:

Stored size: 1.38 KB

Contents

module Daemonizer
  class DslError < StandardError; end

  class Dsl
    def self.evaluate(gemfile)
      builder = new
      builder.instance_eval(File.read(gemfile.to_s), gemfile.to_s, 1)
      builder.instance_variable_get("@configs")
    end

    def initialize
      @source   = nil
      @options  = {}
      @pool     = :default
      @configs  = {}
    end
    
    def set_option(option, value)
      @options[:handler_options] ||= {}
      @options[:handler_options][option.to_sym] = value
    end
    
    def handler(handler)
      @options[:handler] = handler
    end
        
    def poll_period(seconds)
      @options[:poll_period] = seconds.to_i
    end
    
    def log_file(log)
      @options[:log_file] = log
    end
    
    def workers(num)
      @options[:workers] = num.to_i
    end
    
    def engine(name)
      @options[:engine] = name.to_sym
    end
    
    def before_init(&blk)
      @options[:before_init] = blk
    end
    
    def after_init(&blk)
      @options[:after_init] = blk
    end
    
    def pid_file(pid)
      @options[:pid_file] = pid
    end

    def pool(name, &blk)
      @pool = name.to_sym
      options = @options.dup
      yield
      @configs[@pool] = Config.new(@pool, @options)
    rescue Config::ConfigError => e
      puts "* Error in pool \"#{@pool}\": #{e.to_s}. Skipping..."
    ensure
      @options = options
      @pool = nil
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

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