Module: WhittakerTech::Midas::Bankable
- Extended by:
- ActiveSupport::Concern
- Included in:
- Exchange, Ledger::Posting
- Defined in:
- app/models/concerns/whittaker_tech/midas/bankable.rb
Overview
The Bankable module provides currency and monetary value management functionality for Active Record models. It allows models to have associated monetary values (coins) with different currencies and provides convenient methods for setting, retrieving, and formatting these values.
When included in a model, Bankable automatically sets up a polymorphic association to the Midas::Coin model and provides class methods to define specific monetary attributes.
Associations Created
When included, the module automatically creates:
midas_coins: A polymorphic has_many association to all Coin records associated with this model instance
Methods Created by has_coin
For each coin defined with has_coin :name, the following methods are created:
name: Returns the associated Coin objectname_amount: Returns the Money object representing the amountname_format: Returns a formatted string representation of the amountname_in(currency_code): Converts and formats the coin in another currency (writes an Exchange audit row on every call — seeCoin::Converter)set_name(amount:, currency_code:): Sets the coin value with the given amount and currency
Supported Amount Types
The set_* methods accept amounts in various formats:
- Money objects: Used directly for cents value
- Integer: Treated as cents/minor currency units
- Numeric: Converted to cents using currency-specific decimal places
Currency Configuration
The module uses I18n for currency-specific configuration:
midas.ui.currencies.<ISO_CODE>.decimal_count: Decimal places for specific currencymidas.ui.defaults.decimal_count: Default decimal places (defaults to 2)
Thread Safety
This module is designed to be thread-safe when used with Rails' standard Active Record patterns.
See also: WhittakerTech::Midas::Coin