Class: LogStash::Setting::Integer

Inherits:
Coercible show all
Defined in:
lib/logstash/settings.rb

Direct Known Subclasses

Port, PositiveInteger

Instance Attribute Summary

Attributes inherited from LogStash::Setting

#default, #name

Instance Method Summary collapse

Methods inherited from Coercible

#set

Methods inherited from LogStash::Setting

#==, #reset, #set, #set?, #strict?, #to_hash, #validate_value, #value

Constructor Details

#initialize(name, default = nil, strict = true) ⇒ Integer

Returns a new instance of Integer.



357
358
359
# File 'lib/logstash/settings.rb', line 357

def initialize(name, default=nil, strict=true)
  super(name, ::Integer, default, strict)
end

Instance Method Details

#coerce(value) ⇒ Object



361
362
363
364
365
366
367
368
369
370
371
# File 'lib/logstash/settings.rb', line 361

def coerce(value)
  return value unless value.is_a?(::String)

  coerced_value = Integer(value) rescue nil

  if coerced_value.nil?
    raise ArgumentError.new("Failed to coerce value to Integer. Received #{value} (#{value.class})")
  else
    coerced_value
  end
end