Class: ActsAsCalculator::PublishTemplate

Inherits:
Object
  • Object
show all
Defined in:
lib/acts_as_calculator/publish_template.rb

Overview

Authoring a template body publishes it: a new row, numbered one past its siblings, with the outgoing version demoted by the model's own before_create hook. Never update! on an existing row and never update_all(current:) — the one-current-version index refuses the latter, and the former would rewrite a version the history exists to keep. Rollback is PromoteTemplate, not deleting the row that went wrong.

Class Method Summary collapse

Class Method Details

.call(key:, body:, scope: nil, owner: nil, format: Template::HTML) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/acts_as_calculator/publish_template.rb', line 10

def self.call(key:, body:, scope: nil, owner: nil, format: Template::HTML)
  template = Template.new(key: key.to_s, scope: (scope || DEFAULT_SCOPE).to_s, owner:,
                          body: body.to_s, format: format.to_s, current: true)
  template.version_number = template.next_version_number
  template.save!
  template
end