Class: ActsAsCalculator::PromoteTemplate
- Inherits:
-
Object
- Object
- ActsAsCalculator::PromoteTemplate
- Defined in:
- lib/acts_as_calculator/promote_template.rb
Overview
Rollback. Pointing current at an older row leaves every version in place, which is
what "simple version history for rollback" (docs/PLAN.md) buys over deleting the row
that went wrong or racing MAX(version_number).
Class Method Summary collapse
Class Method Details
.call(template:) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/acts_as_calculator/promote_template.rb', line 8 def self.call(template:) Template.transaction do Template.version_siblings_of(template).current.where.not(id: template.id) .update_all(current: false, updated_at: Time.current) # A caller's copy of an already-demoted row still reads `current == true` in memory # — publishing a newer version demotes it with update_all — so without this the # write below looks like a no-op change and never reaches the database. template.reload.update!(current: true) end template end |