Skip to content

Add Money.with_bank for Dynamic Currency Stores#1145

Merged
yukideluxe merged 5 commits intoRubyMoney:mainfrom
pranavbabu:main
Jul 23, 2025
Merged

Add Money.with_bank for Dynamic Currency Stores#1145
yukideluxe merged 5 commits intoRubyMoney:mainfrom
pranavbabu:main

Conversation

@pranavbabu
Copy link
Contributor

After some #discussions with @yukideluxe it seems like this library is a better place for this #PR.

This PR introduces the Money.with_bank method, allowing developers to assign different currency stores (banks) dynamically within a scoped block. This is particularly useful for loading custom exchange rates per user session.

Key Changes

  • Implemented Money.with_bank(bank_instance), enabling temporary overrides of the default bank.
  • Ensures thread safety by restoring the original bank after execution.

Copy link
Member

@sunny sunny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much better indeed, love the addition of the spec for thread-safety as well.

@sunny
Copy link
Member

sunny commented Jul 15, 2025

Can you add a CHANGELOG entry? 🙏🏻

Copy link
Contributor

@pawelma pawelma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the addition, left some comments, mostly nitpicky 😅

Copy link
Member

@yukideluxe yukideluxe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry the delay! thanks for all the changes! this gem uses rbs for typing the method. Would you mind adding that in a similar fashion to

# Temporarily changes the rounding mode in a given block.
#
# @param [BigDecimal::ROUND_MODE] mode
#
# @yield The block within which rounding mode will be changed. Its return
# value will also be the return value of the whole method.
#
# @return [Object] block results
#
# @example
# fee = Money.with_rounding_mode(BigDecimal::ROUND_HALF_DOWN) do
# Money.new(1200) * BigDecimal('0.029')
# end
def self.with_rounding_mode: (untyped mode) { () -> untyped } -> untyped

🙏🏻

last thing and I meeeergeeeee

@pranavbabu
Copy link
Contributor Author

@yukideluxe Lets hope I've done it right :D

Copy link
Member

@yukideluxe yukideluxe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me! thanks! 🙏🏻

@yukideluxe yukideluxe merged commit e833146 into RubyMoney:main Jul 23, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants