Sha256: ef6e96369ebeef2a31275d591f10f0ac7be0c5d2c101fac1e546f689516acf66

Contents?: true

Size: 719 Bytes

Versions: 38

Compression:

Stored size: 719 Bytes

Contents

module Daemonizer
  class Option
    class OptionError < StandardError; end
         
    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
    
    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
    
  end
end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
daemonizer-0.4.18 lib/daemonizer/option.rb
daemonizer-0.4.17 lib/daemonizer/option.rb
daemonizer-0.4.16 lib/daemonizer/option.rb
daemonizer-0.4.15 lib/daemonizer/option.rb
daemonizer-0.4.14 lib/daemonizer/option.rb
daemonizer-0.4.13 lib/daemonizer/option.rb
daemonizer-0.4.12 lib/daemonizer/option.rb
daemonizer-0.4.11 lib/daemonizer/option.rb
daemonizer-0.4.10 lib/daemonizer/option.rb
daemonizer-0.4.9 lib/daemonizer/option.rb
daemonizer-0.4.8 lib/daemonizer/option.rb
daemonizer-0.4.7 lib/daemonizer/option.rb
daemonizer-0.4.6 lib/daemonizer/option.rb
daemonizer-0.4.5 lib/daemonizer/option.rb
daemonizer-0.4.4 lib/daemonizer/option.rb
daemonizer-0.4.3 lib/daemonizer/option.rb
daemonizer-0.4.2 lib/daemonizer/option.rb
daemonizer-0.4.1 lib/daemonizer/option.rb
daemonizer-0.4.0 lib/daemonizer/option.rb
daemonizer-0.3.10 lib/daemonizer/option.rb