Class: LogStash::Setting::PortRange
- Inherits:
-
Coercible
- Object
- LogStash::Setting
- Coercible
- LogStash::Setting::PortRange
- Defined in:
- lib/logstash/settings.rb
Constant Summary collapse
- PORT_SEPARATOR =
"-"
Instance Attribute Summary
Attributes inherited from LogStash::Setting
Instance Method Summary collapse
- #coerce(value) ⇒ Object
-
#initialize(name, default = nil, strict = true) ⇒ PortRange
constructor
A new instance of PortRange.
- #valid?(range) ⇒ Boolean
- #validate(value) ⇒ Object
Methods inherited from Coercible
Methods inherited from LogStash::Setting
#==, #reset, #set, #set?, #strict?, #to_hash, #validate_value, #value
Methods included from Util::Loggable
included, #logger, #slow_logger
Constructor Details
#initialize(name, default = nil, strict = true) ⇒ PortRange
Returns a new instance of PortRange.
360 361 362 |
# File 'lib/logstash/settings.rb', line 360 def initialize(name, default=nil, strict=true) super(name, ::Range, default, strict=true) { |value| valid?(value) } end |
Instance Method Details
#coerce(value) ⇒ Object
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 |
# File 'lib/logstash/settings.rb', line 368 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 # Trap and reraise a more human error 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 |
#valid?(range) ⇒ Boolean
364 365 366 |
# File 'lib/logstash/settings.rb', line 364 def valid?(range) Port::VALID_PORT_RANGE.first <= range.first && Port::VALID_PORT_RANGE.last >= range.last end |
#validate(value) ⇒ Object
387 388 389 390 391 |
# File 'lib/logstash/settings.rb', line 387 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 |