Class: ActsAsCalculatorEditor::CastVariableRows
- Inherits:
-
Object
- Object
- ActsAsCalculatorEditor::CastVariableRows
- Defined in:
- lib/acts_as_calculator_editor/cast_variable_rows.rb
Overview
Form rows in, the variables: list PublishFormulaVersion takes out.
Two things here are not cosmetic. First, an HTML form can post repeated fields either as
an array (version[variables][][name]) or as an index-keyed hash
(version[variables][0][name]); the second is what fields_for emits and the only one
that survives a row whose checkbox is the sole differing field, so both are accepted.
Second, required. CastVariableAttributes treats anything that is not literally
false as true, and an unchecked Rails checkbox posts the string "0" — which would
sail through as required: true and turn an optional variable into one that raises
MissingVariableError at calculation time. The string has to become a real boolean
before it gets anywhere near the core gem.
Constant Summary collapse
- FALSEY =
["0", "false", "off", ""].freeze
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(rows) ⇒ CastVariableRows
constructor
A new instance of CastVariableRows.
Constructor Details
#initialize(rows) ⇒ CastVariableRows
Returns a new instance of CastVariableRows.
23 24 25 |
# File 'lib/acts_as_calculator_editor/cast_variable_rows.rb', line 23 def initialize(rows) @rows = rows end |
Class Method Details
.call ⇒ Object
19 20 21 |
# File 'lib/acts_as_calculator_editor/cast_variable_rows.rb', line 19 def self.call(...) new(...).call end |
Instance Method Details
#call ⇒ Object
27 28 29 |
# File 'lib/acts_as_calculator_editor/cast_variable_rows.rb', line 27 def call normalized_rows.filter_map { |row| variable(row) } end |