Class: LogStash::Setting::Bytes
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) ⇒ Bytes
Returns a new instance of Bytes.
483
484
485
|
# File 'lib/logstash/settings.rb', line 483
def initialize(name, default=nil, strict=true)
super(name, ::Integer, default, strict=true) { |value| valid?(value) }
end
|
Instance Method Details
#coerce(value) ⇒ Object
491
492
493
494
495
496
497
498
499
500
|
# File 'lib/logstash/settings.rb', line 491
def coerce(value)
case value
when ::Numeric
value
when ::String
LogStash::Util::ByteValue.parse(value)
else
raise ArgumentError.new("Could not coerce '#{value}' into a bytes value")
end
end
|
#valid?(value) ⇒ Boolean
487
488
489
|
# File 'lib/logstash/settings.rb', line 487
def valid?(value)
value.is_a?(::Integer) && value >= 0
end
|
#validate(value) ⇒ Object
502
503
504
505
506
|
# File 'lib/logstash/settings.rb', line 502
def validate(value)
unless valid?(value)
raise ArgumentError.new("Invalid byte value \"#{value}\".")
end
end
|