class ByteLimit
Tracks consumed bytes against an optional maximum.
Definitions
def initialize(maximum, name: :size)
Initialize a byte limit.
Signature
-
parameter
maximumInteger | Nil The maximum number of bytes, or nil for no limit.
-
parameter
nameSymbol The name used when reporting a limit violation.
Implementation
def initialize(maximum, name: :size)
if maximum and maximum < 0
raise ArgumentError, "Multipart limits must be non-negative!"
end
@maximum = maximum
@name = name
@size = 0
end
attr :size
The number of bytes consumed.
def consume(size)
Consume the given number of bytes.
Signature
-
parameter
sizeInteger The number of bytes to consume.
-
returns
Integer The total number of bytes consumed.
Implementation
def consume(size)
@size += size
if @maximum and @size > @maximum
raise LimitError, "Multipart #{@name} exceeded limit of #{@maximum}!"
end
return @size
end