Class: LogStash::Setting::Bytes
- Inherits:
-
Coercible
- Object
- LogStash::Setting
- Coercible
- LogStash::Setting::Bytes
- Defined in:
- lib/logstash/settings.rb
Instance Attribute Summary
Attributes inherited from LogStash::Setting
Instance Method Summary collapse
- #coerce(value) ⇒ Object
-
#initialize(name, default = nil, strict = true) ⇒ Bytes
constructor
A new instance of Bytes.
- #valid?(value) ⇒ 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) ⇒ Bytes
Returns a new instance of Bytes.
475 476 477 |
# File 'lib/logstash/settings.rb', line 475 def initialize(name, default=nil, strict=true) super(name, ::Fixnum, default, strict=true) { |value| valid?(value) } end |
Instance Method Details
#coerce(value) ⇒ Object
483 484 485 486 487 488 489 490 491 492 |
# File 'lib/logstash/settings.rb', line 483 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
479 480 481 |
# File 'lib/logstash/settings.rb', line 479 def valid?(value) value.is_a?(Fixnum) && value >= 0 end |
#validate(value) ⇒ Object
494 495 496 497 498 |
# File 'lib/logstash/settings.rb', line 494 def validate(value) unless valid?(value) raise ArgumentError.new("Invalid byte value \"#{value}\".") end end |