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

Constructor Details

#initialize(name, default = nil, strict = true) ⇒ Bytes

Returns a new instance of Bytes.



525
526
527
# File 'lib/logstash/settings.rb', line 525

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

Instance Method Details

#coerce(value) ⇒ Object



533
534
535
536
537
538
539
540
541
542
# File 'lib/logstash/settings.rb', line 533

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:



529
530
531
# File 'lib/logstash/settings.rb', line 529

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

#validate(value) ⇒ Object



544
545
546
547
548
# File 'lib/logstash/settings.rb', line 544

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