Class: LittleGhost::Artifacts::PresentationBudget
- Inherits:
-
Object
- Object
- LittleGhost::Artifacts::PresentationBudget
- Defined in:
- lib/little_ghost/artifacts/presentation_budget.rb
Overview
Bounds transient media delivery without making Tool success depend on delivery order. Overflowing content keeps its materialized reference but is not inserted into the model conversation. # :nodoc:
Constant Summary collapse
- MAX_COUNT =
:nodoc:
4- MAX_BYTES =
8 * 1024 * 1024
Instance Method Summary collapse
- #accept(content) ⇒ Object
-
#initialize ⇒ PresentationBudget
constructor
A new instance of PresentationBudget.
Constructor Details
#initialize ⇒ PresentationBudget
Returns a new instance of PresentationBudget.
12 13 14 15 16 |
# File 'lib/little_ghost/artifacts/presentation_budget.rb', line 12 def initialize @count = 0 @bytes = 0 @mutex = Mutex.new end |
Instance Method Details
#accept(content) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/little_ghost/artifacts/presentation_budget.rb', line 18 def accept(content) blocks = Array(content) bytes = blocks.sum { |block| block_bytes(block) } @mutex.synchronize do return [].freeze if @count + blocks.length > MAX_COUNT return [].freeze if @bytes + bytes > MAX_BYTES @count += blocks.length @bytes += bytes end blocks end |