Class: ActsAsCalculator::FormulaVersionsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/acts_as_calculator/formula_versions_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

Straight through PublishFormulaVersion, so the API takes exactly the same route through the effective-dating rules as the JSON import does: the incumbent is superseded, never rewritten, and a supersede that would leave part of its range with no active version raises PartialSupersedeError — surfaced as a 409, not swallowed.



19
20
21
22
23
24
# File 'app/controllers/acts_as_calculator/formula_versions_controller.rb', line 19

def create
  published = PublishFormulaVersion.(formula:, **version_attributes)

  render json: { version: SerializeFormulaVersion.(version: published, variables: true) },
         status: :created
end

#indexObject



5
6
7
8
9
# File 'app/controllers/acts_as_calculator/formula_versions_controller.rb', line 5

def index
  versions = formula.versions.order(:version_number)

  render json: { versions: versions.map { |version| SerializeFormulaVersion.(version:) } }
end

#showObject



11
12
13
# File 'app/controllers/acts_as_calculator/formula_versions_controller.rb', line 11

def show
  render json: { version: SerializeFormulaVersion.(version:, variables: true) }
end