Module: MoneyAttribute::ColumnTypeValidations Private
- Included in:
- Macro::CompositeClassMethods
- Defined in:
- lib/money_attribute/column_type_validations.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Shared column-type validation for the money_attribute and money_amount
macros.
Included by Macro::CompositeClassMethods and MoneyAmount. Raises when a backing column uses a type that cannot store a money amount or currency code.
Constant Summary collapse
- VALID_AMOUNT_TYPES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
%i[integer bigint decimal].freeze
- VALID_CURRENCY_TYPES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
%i[string text].freeze
Instance Method Summary collapse
-
#assert_valid_amount_column!(attr_name, column_name, column) ⇒ void
private
Validates that a column can store a money amount.
-
#assert_valid_currency_column!(attr_name, column_name, column) ⇒ void
private
Validates that a column can store a currency code.
Instance Method Details
#assert_valid_amount_column!(attr_name, column_name, column) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Validates that a column can store a money amount.
23 24 25 26 27 28 29 |
# File 'lib/money_attribute/column_type_validations.rb', line 23 def assert_valid_amount_column!(attr_name, column_name, column) return if VALID_AMOUNT_TYPES.include?(column.type) raise ArgumentError, "`:#{attr_name}` amount column `#{column_name}` must be a numeric type " \ "(integer, bigint, or decimal), got `#{column.type}`" end |
#assert_valid_currency_column!(attr_name, column_name, column) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Validates that a column can store a currency code.
39 40 41 42 43 44 45 |
# File 'lib/money_attribute/column_type_validations.rb', line 39 def assert_valid_currency_column!(attr_name, column_name, column) return if VALID_CURRENCY_TYPES.include?(column.type) raise ArgumentError, "`:#{attr_name}` currency column `#{column_name}` must be a string type " \ "(string or text), got `#{column.type}`" end |