Class: LogStash::Setting::PortRange
Constant Summary
collapse
- PORT_SEPARATOR =
"-"
Instance Attribute Summary
#default, #name
Instance Method Summary
collapse
Methods inherited from Coercible
#set
#==, #reset, #set, #set?, #strict?, #to_hash, #validate_value, #value
Constructor Details
#initialize(name, default = nil, strict = true) ⇒ PortRange
Returns a new instance of PortRange.
401
402
403
|
# File 'lib/logstash/settings.rb', line 401
def initialize(name, default=nil, strict=true)
super(name, ::Range, default, strict=true) { |value| valid?(value) }
end
|
Instance Method Details
#coerce(value) ⇒ Object
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
|
# File 'lib/logstash/settings.rb', line 409
def coerce(value)
case value
when ::Range
value
when ::Integer
value..value
when ::String
first, last = value.split(PORT_SEPARATOR)
last = first if last.nil?
begin
(Integer(first))..(Integer(last))
rescue ArgumentError raise ArgumentError.new("Could not coerce #{value} into a port range")
end
else
raise ArgumentError.new("Could not coerce #{value} into a port range")
end
end
|
#validate(value) ⇒ Object
428
429
430
431
432
|
# File 'lib/logstash/settings.rb', line 428
def validate(value)
unless valid?(value)
raise ArgumentError.new("Invalid value \"#{value}, valid options are within the range of #{Port::VALID_PORT_RANGE.first}-#{Port::VALID_PORT_RANGE.last}")
end
end
|