Class: Money::Config
- Inherits:
-
Object
- Object
- Money::Config
- Defined in:
- lib/money/config.rb
Constant Summary collapse
- CONFIG_THREAD =
:shopify_money__configs
Instance Attribute Summary collapse
-
#default_allocation_strategy ⇒ Object
Returns the value of attribute default_allocation_strategy.
-
#default_currency ⇒ Object
(also: #currency)
Returns the value of attribute default_currency.
-
#default_subunit_format ⇒ Object
Returns the value of attribute default_subunit_format.
-
#experimental_crypto_currencies ⇒ Object
Returns the value of attribute experimental_crypto_currencies.
-
#experimental_custom_currency_path ⇒ Object
Returns the value of attribute experimental_custom_currency_path.
-
#legacy_json_format ⇒ Object
Returns the value of attribute legacy_json_format.
Class Method Summary collapse
- .configure_current(**configs, &block) ⇒ Object
- .current ⇒ Object
- .current=(config) ⇒ Object
- .global ⇒ Object
- .reset_current ⇒ Object
Instance Method Summary collapse
- #experimental_crypto_currencies! ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #legacy_json_format! ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
70 71 72 73 74 75 76 77 |
# File 'lib/money/config.rb', line 70 def initialize @default_currency = nil @legacy_json_format = false @experimental_crypto_currencies = false @default_subunit_format = :iso4217 @experimental_custom_currency_path = nil @default_allocation_strategy = :roundrobin end |
Instance Attribute Details
#default_allocation_strategy ⇒ Object
Returns the value of attribute default_allocation_strategy.
44 45 46 |
# File 'lib/money/config.rb', line 44 def default_allocation_strategy @default_allocation_strategy end |
#default_currency ⇒ Object Also known as: currency
Returns the value of attribute default_currency.
46 47 48 |
# File 'lib/money/config.rb', line 46 def default_currency @default_currency end |
#default_subunit_format ⇒ Object
Returns the value of attribute default_subunit_format.
44 45 46 |
# File 'lib/money/config.rb', line 44 def default_subunit_format @default_subunit_format end |
#experimental_crypto_currencies ⇒ Object
Returns the value of attribute experimental_crypto_currencies.
44 45 46 |
# File 'lib/money/config.rb', line 44 def experimental_crypto_currencies @experimental_crypto_currencies end |
#experimental_custom_currency_path ⇒ Object
Returns the value of attribute experimental_custom_currency_path.
44 45 46 |
# File 'lib/money/config.rb', line 44 def experimental_custom_currency_path @experimental_custom_currency_path end |
#legacy_json_format ⇒ Object
Returns the value of attribute legacy_json_format.
44 45 46 |
# File 'lib/money/config.rb', line 44 def legacy_json_format @legacy_json_format end |
Class Method Details
.configure_current(**configs, &block) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/money/config.rb', line 20 def configure_current(**configs, &block) old_config = current.dup current.tap do |config| configs.each do |k, v| config.public_send("#{k}=", v) end end yield ensure self.current = old_config end |
.current ⇒ Object
12 13 14 |
# File 'lib/money/config.rb', line 12 def current thread_local_config[Fiber.current.object_id] ||= global.dup end |
.current=(config) ⇒ Object
16 17 18 |
# File 'lib/money/config.rb', line 16 def current=(config) thread_local_config[Fiber.current.object_id] = config end |
.global ⇒ Object
8 9 10 |
# File 'lib/money/config.rb', line 8 def global @config ||= new end |
.reset_current ⇒ Object
32 33 34 35 |
# File 'lib/money/config.rb', line 32 def reset_current thread_local_config.delete(Fiber.current.object_id) Thread.current[CONFIG_THREAD] = nil if thread_local_config.empty? end |
Instance Method Details
#experimental_crypto_currencies! ⇒ Object
66 67 68 |
# File 'lib/money/config.rb', line 66 def experimental_crypto_currencies! @experimental_crypto_currencies = true end |
#legacy_json_format! ⇒ Object
62 63 64 |
# File 'lib/money/config.rb', line 62 def legacy_json_format! @legacy_json_format = true end |