Class: ActsAsCalculatorEditor::ExportFormulas

Inherits:
Object
  • Object
show all
Defined in:
lib/acts_as_calculator_editor/export_formulas.rb

Overview

The formulas section of an import document — which is not the shape SerializeFormula emits (docs/core-gem-contract.md §4.2). Four differences, each of which would silently produce a file that does not round-trip:

  • one flat entry per version, repeating key/scope/owner, rather than a formula with a nested versions array;
  • owner as a {type, id} object, omitted entirely when nil;
  • no id, formula_id, version_number, created_at or updated_at — none of them are import keys;
  • required written out as a real boolean, because the import default is "anything not literally false" and omitting it is therefore not the same as round-tripping it.

Version order is load-bearing, not cosmetic. SupersedeFormulaVersions applies entries in file order, so a version that takes over the tail of a range has to land after the one giving it up; an out-of-order export re-imports straight into PartialSupersedeError.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key: nil, scope: nil, full_history: false) ⇒ ExportFormulas

Returns a new instance of ExportFormulas.



25
26
27
28
29
# File 'lib/acts_as_calculator_editor/export_formulas.rb', line 25

def initialize(key: nil, scope: nil, full_history: false)
  @key = key
  @scope = scope
  @full_history = full_history
end

Class Method Details

.callObject



21
22
23
# File 'lib/acts_as_calculator_editor/export_formulas.rb', line 21

def self.call(...)
  new(...).call
end

Instance Method Details

#callObject



31
32
33
# File 'lib/acts_as_calculator_editor/export_formulas.rb', line 31

def call
  formulas.flat_map { |formula| versions(formula).map { |version| entry(formula, version) } }
end