Class: ActsAsCalculatorEditor::PublishLookupTable

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

Overview

The core gem ships no controller for lookup tables and no Decree for authoring one outside an import document (docs/core-gem-contract.md §4.4). This builds the single lookup_tables entry that document would have carried and hands it to ActsAsCalculator::ImportLookupTable.

Going through that Decree rather than writing table.entries.create! here is the whole point: it carries guard_against_rewriting_audited_brackets, which refuses to change entries an active or retired formula version resolves to. That guard is what stops a bracket edit from retroactively changing what an audited calculation was measured against, and it exists in exactly one place.

The transaction is ours because ImportLookupTable deletes the old entries before writing the new ones and leaves the savepoint to its caller — normally ImportDefinitions. Without one, an entry the model rejects would leave the table emptied.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key:, scope: nil, owner: nil, entries: []) ⇒ PublishLookupTable

Returns a new instance of PublishLookupTable.



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

def initialize(key:, scope: nil, owner: nil, entries: [])
  @key = key.to_s.strip
  @scope = (scope.presence || ActsAsCalculator::DEFAULT_SCOPE).to_s.strip
  @owner = owner
  @entries = entries
end

Class Method Details

.callObject



20
21
22
# File 'lib/acts_as_calculator_editor/publish_lookup_table.rb', line 20

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

Instance Method Details

#callObject



31
32
33
34
35
36
37
# File 'lib/acts_as_calculator_editor/publish_lookup_table.rb', line 31

def call
  ActsAsCalculator::Record.transaction(requires_new: true) do
    ActsAsCalculator::ImportLookupTable.(attributes:)
  end

  ActsAsCalculator::LookupTable.owned_by(owner).find_by!(key:, scope:)
end