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.
359
360
361
|
# File 'lib/logstash/settings.rb', line 359
def initialize(name, default=nil, strict=true)
super(name, ::Range, default, strict=true) { |value| valid?(value) }
end
|
Instance Method Details
#coerce(value) ⇒ Object
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
|
# File 'lib/logstash/settings.rb', line 367
def coerce(value)
case value
when ::Range
value
when ::Fixnum
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
386
387
388
389
390
|
# File 'lib/logstash/settings.rb', line 386
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
|