Class: Daemonizer::Option

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

Defined Under Namespace

Classes: OptionError

Instance Method Summary collapse

Constructor Details

#initialize(option, value, auto_eval = false) ⇒ Option

Returns a new instance of Option.



5
6
7
8
9
10
11
12
# File 'lib/daemonizer/option.rb', line 5

def initialize(option, value, auto_eval = false)
  @option = option
  @value = value
  @auto_eval = auto_eval
  if @auto_eval && !@value.is_a?(Proc)
    raise OptionError, "auto_apply can be used only with callable option"
  end
end

Instance Method Details

#value(handler = nil) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/daemonizer/option.rb', line 14

def value(handler = nil)
  if @auto_eval && @value.is_a?(Proc) 
    if handler && handler.worker_id && handler.workers_count
      return @value.call(handler.worker_id, handler.workers_count)
    else
      raise OptionError, "value called before handler initialized"
    end
  else
    @value
  end
end