Class: LogStash::Setting::Bytes

Inherits:
Coercible show all
Defined in:
lib/logstash/settings.rb

Instance Attribute Summary

Attributes inherited from LogStash::Setting

#default, #name

Instance Method Summary collapse

Methods inherited from Coercible

#set

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.



456
457
458
# File 'lib/logstash/settings.rb', line 456

def initialize(name, default=nil, strict=true)
  super(name, ::Fixnum, default, strict=true) { |value| valid?(value) }
end

Instance Method Details

#coerce(value) ⇒ Object



464
465
466
467
468
469
470
471
472
473
# File 'lib/logstash/settings.rb', line 464

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

Returns:



460
461
462
# File 'lib/logstash/settings.rb', line 460

def valid?(value)
  value.is_a?(Fixnum) && value >= 0
end

#validate(value) ⇒ Object



475
476
477
478
479
# File 'lib/logstash/settings.rb', line 475

def validate(value)
  unless valid?(value)
    raise ArgumentError.new("Invalid byte value \"#{value}\".")
  end
end