Class: Daemonizer::Dsl

Inherits:
Object
  • Object
show all
Defined in:
lib/daemonizer/dsl.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDsl

Returns a new instance of Dsl.



10
11
12
13
14
15
# File 'lib/daemonizer/dsl.rb', line 10

def initialize
  @source   = nil
  @options  = {}
  @pool     = :default
  @configs  = {}
end

Class Method Details

.evaluate(gemfile) ⇒ Object



4
5
6
7
8
# File 'lib/daemonizer/dsl.rb', line 4

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

Instance Method Details

#after_fork(&block) ⇒ Object



28
29
30
# File 'lib/daemonizer/dsl.rb', line 28

def after_fork(&block)
  set_option :after_fork, block
end

#handler(handler) ⇒ Object



36
37
38
# File 'lib/daemonizer/dsl.rb', line 36

def handler(handler)
  @options[:handler] = handler
end

#log_file(log) ⇒ Object



44
45
46
# File 'lib/daemonizer/dsl.rb', line 44

def log_file(log)
  @options[:log_file] = log
end

#not_cow_friendlyObject



32
33
34
# File 'lib/daemonizer/dsl.rb', line 32

def not_cow_friendly
  @options[:cow_friendly] = false
end

#pid_file(pid) ⇒ Object



60
61
62
# File 'lib/daemonizer/dsl.rb', line 60

def pid_file(pid)
  @options[:pid_file] = pid
end

#poll_period(seconds) ⇒ Object



40
41
42
# File 'lib/daemonizer/dsl.rb', line 40

def poll_period(seconds)
  @options[:poll_period] = seconds.to_i
end

#pool(name, &blk) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/daemonizer/dsl.rb', line 64

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

#prepare(&blk) ⇒ Object



52
53
54
# File 'lib/daemonizer/dsl.rb', line 52

def prepare(&blk)
  @options[:prepare] = blk
end

#set_option(option, value = nil, &block) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/daemonizer/dsl.rb', line 17

def set_option(option, value = nil, &block)
  @options[:handler_options] ||= {}
  if value
    @options[:handler_options][option.to_sym] = Daemonizer::Option.new(option, value)
  elsif block_given?
    @options[:handler_options][option.to_sym] = Daemonizer::Option.new(option, block, true)
  else
    raise DslError, "you should supply block or value to :set_option"
  end
end

#start(&blk) ⇒ Object



56
57
58
# File 'lib/daemonizer/dsl.rb', line 56

def start(&blk)
  @options[:start] = blk
end

#workers(num) ⇒ Object



48
49
50
# File 'lib/daemonizer/dsl.rb', line 48

def workers(num)
  @options[:workers] = num.to_i
end