Class: ActsAsCalculator::RenderLiquid::IterationBudget
- Inherits:
-
Object
- Object
- ActsAsCalculator::RenderLiquid::IterationBudget
- Defined in:
- lib/acts_as_calculator/render_liquid.rb
Instance Method Summary collapse
-
#initialize(limit) ⇒ IterationBudget
constructor
A new instance of IterationBudget.
-
#reserve(collection) ⇒ Object
Checked against the collection as declared, before Liquid reaches Range#to_a on it —
{% for i in (1..2000000000) %}is a heap bomb no post-hoc count can undo. - #spend(count) ⇒ Object
Constructor Details
#initialize(limit) ⇒ IterationBudget
Returns a new instance of IterationBudget.
37 38 39 40 |
# File 'lib/acts_as_calculator/render_liquid.rb', line 37 def initialize(limit) @limit = limit @remaining = limit end |
Instance Method Details
#reserve(collection) ⇒ Object
Checked against the collection as declared, before Liquid reaches Range#to_a on
it — {% for i in (1..2000000000) %} is a heap bomb no post-hoc count can undo.
44 45 46 47 48 |
# File 'lib/acts_as_calculator/render_liquid.rb', line 44 def reserve(collection) size = countable_size(collection) exhausted! if !size.nil? && size > remaining end |
#spend(count) ⇒ Object
50 51 52 53 54 |
# File 'lib/acts_as_calculator/render_liquid.rb', line 50 def spend(count) @remaining -= count exhausted! if remaining.negative? end |