Class: ActsAsCalculatorEditor::LookupTablesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- ActsAsCalculatorEditor::LookupTablesController
- Defined in:
- app/controllers/acts_as_calculator_editor/lookup_tables_controller.rb
Overview
The core gem has no controller, no routes and no serializer for lookup tables
(docs/core-gem-contract.md §4.4) — deliberately, because POST /import is the only path
that enforces the guard against editing brackets an audited formula version resolved to.
This controller is therefore the only lookup-table authoring surface there is, and it
keeps that property by writing exclusively through ImportLookupTable
(via PublishLookupTable) rather than touching entries directly.
This matters because a lookup table is not decoration: a variable with
source_type: "lookup" cannot evaluate without one.
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
-
#edit ⇒ Object
keyandscopeare not editable. - #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'app/controllers/acts_as_calculator_editor/lookup_tables_controller.rb', line 42 def create @form = submitted_form @entry_rows = submitted_entry_rows rescuing_core_errors(:new) do created = PublishLookupTable.(key: @form["key"], scope: @form["scope"], owner: current_owner, entries: @entry_rows) redirect_to lookup_table_path(created), notice: "Created lookup table #{created.key}." end end |
#destroy ⇒ Object
65 66 67 68 69 70 71 72 73 74 |
# File 'app/controllers/acts_as_calculator_editor/lookup_tables_controller.rb', line 65 def destroy @lookup_table = lookup_table @entries = entries @used_by = references rescuing_core_errors(:show) do DeleteLookupTable.(lookup_table: @lookup_table) redirect_to lookup_tables_path, notice: "Deleted lookup table #{@lookup_table.key}." end end |
#edit ⇒ Object
key and scope are not editable. ImportLookupTable keys on [key, scope, owner],
so a "rename" would silently create a second table and leave every formula variable
still pointing at the old one — which would keep calculating, against brackets the
operator believes they just changed. Entries are what an edit changes; a new key is a
new table.
36 37 38 39 40 |
# File 'app/controllers/acts_as_calculator_editor/lookup_tables_controller.rb', line 36 def edit @lookup_table = lookup_table @form = { "key" => lookup_table.key, "scope" => lookup_table.scope } @entry_rows = entries.map { |entry| entry_row(entry) } end |
#index ⇒ Object
14 15 16 17 18 |
# File 'app/controllers/acts_as_calculator_editor/lookup_tables_controller.rb', line 14 def index @lookup_tables = filter_by_key_and_scope( ActsAsCalculator::LookupTable.includes(:entries).order(:scope, :key, :id) ) end |
#new ⇒ Object
26 27 28 29 |
# File 'app/controllers/acts_as_calculator_editor/lookup_tables_controller.rb', line 26 def new @form = { "key" => "", "scope" => ActsAsCalculator::DEFAULT_SCOPE } @entry_rows = [] end |
#show ⇒ Object
20 21 22 23 24 |
# File 'app/controllers/acts_as_calculator_editor/lookup_tables_controller.rb', line 20 def show @lookup_table = lookup_table @entries = entries @used_by = references end |
#update ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 |
# File 'app/controllers/acts_as_calculator_editor/lookup_tables_controller.rb', line 53 def update @lookup_table = lookup_table @form = { "key" => lookup_table.key, "scope" => lookup_table.scope } @entry_rows = submitted_entry_rows rescuing_core_errors(:edit) do updated = PublishLookupTable.(key: @form["key"], scope: @form["scope"], owner: lookup_table.owner, entries: @entry_rows) redirect_to lookup_table_path(updated), notice: "Updated lookup table #{updated.key}." end end |