Module WhittakerTech::Midas ¶
WhittakerTech::Midas is a Rails engine for multi-currency monetary value
management. It replaces scattered *_cents and *_currency columns with a
single polymorphic Coin model backed by a centralized midas_coins table.
Configuration¶
Table namespace (PostgreSQL schema)¶
By default all coins are stored in midas_coins. To place the table inside a
PostgreSQL schema set table_namespace in an initializer:
WhittakerTech::Midas.table_namespace = 'finance'
# => table becomes finance.coins
Bidirectional text¶
Currency display direction defaults to LTR for every currency code. Override individual currencies as needed:
WhittakerTech::Midas.currency_directions['ILS'] = :rtl
WhittakerTech::Midas.currency_directions['AED'] = :rtl
See also:
CoinCoin::Arithmetic-
Bankable -
@since 0.1.0
Constants¶
DEFAULT_ROUNDING_POLICY ¶
The rounding policy applied when no explicit policy is supplied.
- @return [Symbol]
- @since 0.1.0
ROUNDING_POLICIES ¶
Rounding strategies available for division operations.
Each value is a lambda that accepts a Float and returns a rounded value.
Rounding keys:
:round: Round half-up (standard commercial rounding):ceil: Always round up (ceiling):floor: Always round down (floor / truncate):bankers: Round half-to-even (banker's rounding)- @return [Hash{Symbol => Proc}]
- @since 0.1.0
VERSION ¶
Not documented.
Public Class Methods¶
currency_direction_for(currency_code) ¶
Returns the configured display direction for the given currency code.
Falls back to :ltr for any currency not explicitly configured.
- @param
currency_code[String] ISO 4217 currency code, e.g."USD" - @return [Symbol]
:ltror:rtl - @since 0.1.0
currency_directions() ¶
Per-currency display direction map. Defaults all currencies to
:ltr.
Modify to configure RTL currencies in your initializer:
WhittakerTech::Midas.currency_directions['ILS'] = :rtl
- @return [Hash{String => Symbol}] maps uppercased ISO currency code to
:ltror:rtl - @since 0.1.0
reset_configuration!() ¶
Resets all mutable configuration to defaults.
Intended for use in test suite after blocks when specs mutate engine-level
configuration.
- @return [void]
- @since 0.1.0
table_name(name) ¶
Resolves the fully-qualified table name for a given base name.
- @param
name[String] base table name, e.g."coins" - @raise [RuntimeError] if
table_namespaceis set and the adapter is not PostgreSQL - @return [String] the namespaced table name
- @since 0.1.0
Public Instance Methods¶
deprecation_behavior() ¶
Controls how deprecation notices are emitted.
Allowed values:
:warn: Prints to STDERR viaKernel.warn(default):raise: RaisesDeprecation::DeprecationError:silence: Suppresses all notices- @return [Symbol]
- @since 0.1.0
table_namespace() ¶
Optional PostgreSQL schema name used to namespace the coins table.
When nil (default) the table is created as midas_coins. When set, the
table becomes <namespace>.coins and requires a PostgreSQL adapter.
- @return [String, nil]
- @since 0.1.0