Class: ActsAsCalculator::SerializeFormula

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

Overview

Identity only by default — content lives on the versions, and a formulas index that inlined every version of every formula would be the wrong default for the one endpoint a host hits most.

Class Method Summary collapse

Class Method Details

.call(formula:, versions: false) ⇒ Object



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

def self.call(formula:, versions: false)
  payload = { id: formula.id, key: formula.key, scope: formula.scope,
              owner_type: formula.owner_type, owner_id: formula.owner_id,
              created_at: formula.created_at&.iso8601, updated_at: formula.updated_at&.iso8601 }
  return payload unless versions

  payload.merge(versions: formula.versions.order(:version_number)
                                 .map { |version| SerializeFormulaVersion.(version:) })
end