Skip to content

Money.default_currency=() accepts a lambda.#359

Merged
semmons99 merged 1 commit intoRubyMoney:masterfrom
Nerian:accept_lambda
Jan 20, 2014
Merged

Money.default_currency=() accepts a lambda.#359
semmons99 merged 1 commit intoRubyMoney:masterfrom
Nerian:accept_lambda

Conversation

@Nerian
Copy link
Contributor

@Nerian Nerian commented Jan 19, 2014

Hi,

This pull request modifies Money to accept a lambda when setting a default_currency.

This is useful for multithreaded environments, like a Ruby on Rails application running on Puma. I am using it like this:

MoneyRails.configure do |config|

  # To set the default currency
  config.default_currency = lambda { RequestStore.store[:default_currency] || :eur }
end
class ApplicationController < ActionController::Base

  before_filter :set_currency

  def set_currency
    RequestStore.store[:default_currency] = current_clinic.currency
  end
end

There are some minor changes to do on money-rails for this to work. I will make PR too in that repo if this gets merged in.

@semmons99
Copy link
Member

Excellent. 👍

semmons99 added a commit that referenced this pull request Jan 20, 2014
Money.default_currency=() accepts a lambda.
@semmons99 semmons99 merged commit 130ad72 into RubyMoney:master Jan 20, 2014
Copy link
Contributor

Choose a reason for hiding this comment

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

after should go just after before, it's a convention in this file and in general.

Copy link
Member

Choose a reason for hiding this comment

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

👍

Copy link
Member

Choose a reason for hiding this comment

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

Feel free to submit a PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

@semmons99 done

@Nerian Nerian deleted the accept_lambda branch June 17, 2014 13:14
@Nerian Nerian restored the accept_lambda branch June 17, 2014 13:14
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