Class: Protocol::Multipart::ByteLimit
- Inherits:
-
Object
- Object
- Protocol::Multipart::ByteLimit
- Defined in:
- lib/protocol/multipart/byte_limit.rb
Overview
Tracks consumed bytes against an optional maximum.
Instance Attribute Summary collapse
-
#size ⇒ Object
readonly
The number of bytes consumed.
Instance Method Summary collapse
-
#consume(size) ⇒ Object
Consume the given number of bytes.
-
#initialize(maximum, name: :size) ⇒ ByteLimit
constructor
Initialize a byte limit.
Constructor Details
#initialize(maximum, name: :size) ⇒ ByteLimit
Initialize a byte limit.
13 14 15 16 17 18 19 20 21 |
# File 'lib/protocol/multipart/byte_limit.rb', line 13 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 |
Instance Attribute Details
#size ⇒ Object (readonly)
The number of bytes consumed.
24 25 26 |
# File 'lib/protocol/multipart/byte_limit.rb', line 24 def size @size end |
Instance Method Details
#consume(size) ⇒ Object
Consume the given number of bytes.
29 30 31 32 33 34 35 36 37 |
# File 'lib/protocol/multipart/byte_limit.rb', line 29 def consume(size) @size += size if @maximum and @size > @maximum raise RangeError, "Multipart #{@name} exceeded limit of #{@maximum}!" end return @size end |