money 6.13.4 → 6.13.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: ca21de22dba51f2c9b00ca1301f5d21ea936767a
4
- data.tar.gz: 1cfb4f822e6f7a948f8ff31955422372658c0394
2
+ SHA256:
3
+ metadata.gz: d517e06943977328b7ad20b73554269088b01b947c280cc454f87ef88dfb8e2d
4
+ data.tar.gz: 2c7c5ba4c19a5ff2413273cb64443b5628468b083f260f8cdf49c133e3b7319e
5
5
  SHA512:
6
- metadata.gz: 207a714b183381a90c2c46f1b4cef2a9246e5a8be0f0c30a088b4d71c98fbdc814e356cb3dac8d2301eefd7d18cf7f70914f6ef9e314975039edbe5bc2b2a7c8
7
- data.tar.gz: 8dca4236991ae835e822cd09bc4e0a6fbeb0b2fee52bb85be3dbb38cfa07f7fa60bbde94045b9a643071435126954324da1aa00065af9ab79f2cd961ee50b7d9
6
+ metadata.gz: f1cbd0d2e7f790a00528531b3f325bffb4ee8aef98917cc1c17232684eeb5ffb66ce56ebd0618146302468e1259cb284d3a96e576c4592fc67db41cddfb14a64
7
+ data.tar.gz: 1d3c22cde9570f93dba5f86952b35a952b0dbfc95262c051e36f0829f8ac06669181cf0b10524d0df44123ae2095c60e8301af999f89a1119ac6d252fddcb6dc
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 6.13.5
4
+ - Raise warning on using Money.default_currency
5
+ - Raise warning on using default Money.rounding_mode
6
+ - Add Second Ouguiya MRU 929 to currency iso file
7
+ - Add symbol for UZS
8
+ - Use monitor for recursive mutual exclusion in RatesStore::Memory
9
+ - Allow passing store as a string to Money::Bank::VariableExchange (to support Rails 6)
10
+
3
11
  ## 6.13.4
4
12
  - Update currency config for Zambian Kwacha (ZMW)
5
13
  - Do not modify options passed to FormattingRules
data/README.md CHANGED
@@ -21,7 +21,7 @@ A Ruby Library for dealing with money and currency conversion.
21
21
 
22
22
  ### Features
23
23
 
24
- - Provides a `Money` class which encapsulates all information about an certain
24
+ - Provides a `Money` class which encapsulates all information about a certain
25
25
  amount of money, such as its value and its currency.
26
26
  - Provides a `Money::Currency` class which encapsulates all information about
27
27
  a monetary unit.
@@ -334,6 +334,8 @@ end
334
334
  Now you can use it with the default bank.
335
335
 
336
336
  ```ruby
337
+ # For Rails 6 pass model name as a string to make it compatible with zeitwerk
338
+ # Money.default_bank = Money::Bank::VariableExchange.new("ExchangeRate")
337
339
  Money.default_bank = Money::Bank::VariableExchange.new(ExchangeRate)
338
340
 
339
341
  # Add to the underlying store
@@ -60,6 +60,22 @@
60
60
  "iso_numeric": "428",
61
61
  "smallest_denomination": 1
62
62
  },
63
+ "mro": {
64
+ "priority": 100,
65
+ "iso_code": "MRO",
66
+ "name": "Mauritanian Ouguiya",
67
+ "symbol": "UM",
68
+ "disambiguate_symbol": "A-UM",
69
+ "alternate_symbols": [],
70
+ "subunit": "Khoums",
71
+ "subunit_to_unit": 5,
72
+ "symbol_first": false,
73
+ "html_entity": "",
74
+ "decimal_mark": ".",
75
+ "thousands_separator": ",",
76
+ "iso_numeric": "478",
77
+ "smallest_denomination": 1
78
+ },
63
79
  "mtl": {
64
80
  "priority": 100,
65
81
  "iso_code": "MTL",
@@ -1412,9 +1412,9 @@
1412
1412
  "iso_numeric": "446",
1413
1413
  "smallest_denomination": 10
1414
1414
  },
1415
- "mro": {
1415
+ "mru": {
1416
1416
  "priority": 100,
1417
- "iso_code": "MRO",
1417
+ "iso_code": "MRU",
1418
1418
  "name": "Mauritanian Ouguiya",
1419
1419
  "symbol": "UM",
1420
1420
  "alternate_symbols": [],
@@ -1424,7 +1424,7 @@
1424
1424
  "html_entity": "",
1425
1425
  "decimal_mark": ".",
1426
1426
  "thousands_separator": ",",
1427
- "iso_numeric": "478",
1427
+ "iso_numeric": "929",
1428
1428
  "smallest_denomination": 1
1429
1429
  },
1430
1430
  "mur": {
@@ -2260,7 +2260,7 @@
2260
2260
  "priority": 100,
2261
2261
  "iso_code": "UZS",
2262
2262
  "name": "Uzbekistan Som",
2263
- "symbol": "",
2263
+ "symbol": "so'm",
2264
2264
  "alternate_symbols": ["so‘m", "сўм", "сум", "s", "с"],
2265
2265
  "subunit": "Tiyin",
2266
2266
  "subunit_to_unit": 100,
@@ -42,7 +42,7 @@ class Money
42
42
  # bank.get_rate 'USD', 'CAD'
43
43
  class VariableExchange < Base
44
44
 
45
- attr_reader :mutex, :store
45
+ attr_reader :mutex
46
46
 
47
47
  # Available formats for importing/exporting rates.
48
48
  RATE_FORMATS = [:json, :ruby, :yaml].freeze
@@ -61,6 +61,10 @@ class Money
61
61
  super(&block)
62
62
  end
63
63
 
64
+ def store
65
+ @store.is_a?(String) ? Object.const_get(@store) : @store
66
+ end
67
+
64
68
  def marshal_dump
65
69
  [store.marshal_dump, @rounding_method]
66
70
  end
@@ -414,7 +414,7 @@ class Money
414
414
 
415
415
  # Returns the relation between subunit and unit as a base 10 exponent.
416
416
  #
417
- # Note that MGA and MRO are exceptions and are rounded to 1
417
+ # Note that MGA and MRU are exceptions and are rounded to 1
418
418
  # @see https://en.wikipedia.org/wiki/ISO_4217#Active_codes
419
419
  #
420
420
  # @return [Integer]
@@ -123,19 +123,19 @@ class Money
123
123
  attr_accessor :default_bank, :default_formatting_rules,
124
124
  :use_i18n, :infinite_precision, :conversion_precision,
125
125
  :locale_backend
126
-
127
- # @attr_writer rounding_mode Use this to specify the rounding mode
128
- #
129
- # @!attribute default_currency
130
- # @return [Money::Currency] The default currency, which is used when
131
- # +Money.new+ is called without an explicit currency argument. The
132
- # default value is Currency.new("USD"). The value must be a valid
133
- # +Money::Currency+ instance.
134
- attr_writer :rounding_mode, :default_currency
135
-
136
126
  end
137
127
 
128
+ # @!attribute default_currency
129
+ # @return [Money::Currency] The default currency, which is used when
130
+ # +Money.new+ is called without an explicit currency argument. The
131
+ # default value is Currency.new("USD"). The value must be a valid
132
+ # +Money::Currency+ instance.
138
133
  def self.default_currency
134
+ if @using_deprecated_default_currency
135
+ warn '[WARNING] The default currency will change to `nil` in the next major release. Make ' \
136
+ 'sure to set it explicitly using `Money.default_currency=` to avoid potential issues'
137
+ end
138
+
139
139
  if @default_currency.respond_to?(:call)
140
140
  Money::Currency.new(@default_currency.call)
141
141
  else
@@ -143,10 +143,21 @@ class Money
143
143
  end
144
144
  end
145
145
 
146
+ def self.default_currency=(currency)
147
+ @using_deprecated_default_currency = false
148
+ @default_currency = currency
149
+ end
150
+
146
151
  def self.locale_backend=(value)
147
152
  @locale_backend = value ? LocaleBackend.find(value) : nil
148
153
  end
149
154
 
155
+ # @attr_writer rounding_mode Use this to specify the rounding mode
156
+ def self.rounding_mode=(new_rounding_mode)
157
+ @using_deprecated_default_rounding_mode = false
158
+ @rounding_mode = new_rounding_mode
159
+ end
160
+
150
161
  def self.use_i18n=(value)
151
162
  if value
152
163
  warn '[DEPRECATION] `use_i18n` is deprecated - use `Money.locale_backend = :i18n` instead for locale based formatting'
@@ -163,6 +174,7 @@ class Money
163
174
 
164
175
  # Set the default currency for creating new +Money+ object.
165
176
  self.default_currency = Currency.new("USD")
177
+ @using_deprecated_default_currency = true
166
178
 
167
179
  # Default to using i18n
168
180
  @use_i18n = true
@@ -175,6 +187,7 @@ class Money
175
187
 
176
188
  # Default to bankers rounding
177
189
  self.rounding_mode = BigDecimal::ROUND_HALF_EVEN
190
+ @using_deprecated_default_rounding_mode = true
178
191
 
179
192
  # Default the conversion of Rationals precision to 16
180
193
  self.conversion_precision = 16
@@ -192,10 +205,19 @@ class Money
192
205
  #
193
206
  # @return [BigDecimal::ROUND_MODE] rounding mode
194
207
  def self.rounding_mode(mode = nil)
195
- return Thread.current[:money_rounding_mode] || @rounding_mode unless mode
208
+ if mode
209
+ warn "[DEPRECATION] calling `rounding_mode` with a block is deprecated. Please use `.with_rounding_mode` instead."
210
+ return with_rounding_mode(mode) { yield }
211
+ end
212
+
213
+ return Thread.current[:money_rounding_mode] if Thread.current[:money_rounding_mode]
214
+
215
+ if @using_deprecated_default_rounding_mode
216
+ warn '[WARNING] The default rounding mode will change to `ROUND_HALF_UP` in the next major ' \
217
+ 'release. Set it explicitly using `Money.rounding_mode=` to avoid potential problems.'
218
+ end
196
219
 
197
- warn "[DEPRECATION] calling `rounding_mode` with a block is deprecated. Please use `.with_rounding_mode` instead."
198
- with_rounding_mode(mode) { yield }
220
+ @rounding_mode
199
221
  end
200
222
 
201
223
  # This method temporarily changes the rounding mode. It will then return the
@@ -1,3 +1,5 @@
1
+ require 'monitor'
2
+
1
3
  class Money
2
4
  module RatesStore
3
5
 
@@ -18,10 +20,10 @@ class Money
18
20
  # @param [Hash] opts Optional store options.
19
21
  # @option opts [Boolean] :without_mutex disables the usage of a mutex
20
22
  # @param [Hash] rt Optional initial exchange rate data.
21
- def initialize(opts = {}, rt = {})
22
- @options, @index = opts, rt
23
- @mutex = Mutex.new
24
- @in_transaction = false
23
+ def initialize(opts = {}, rates = {})
24
+ @rates = rates
25
+ @options = opts
26
+ @guard = Monitor.new
25
27
  end
26
28
 
27
29
  # Registers a conversion rate and returns it. Uses +Mutex+ to synchronize data access.
@@ -37,7 +39,9 @@ class Money
37
39
  # store.add_rate("USD", "CAD", 1.24515)
38
40
  # store.add_rate("CAD", "USD", 0.803115)
39
41
  def add_rate(currency_iso_from, currency_iso_to, rate)
40
- transaction { index[rate_key_for(currency_iso_from, currency_iso_to)] = rate }
42
+ @guard.synchronize do
43
+ @rates[rate_key_for(currency_iso_from, currency_iso_to)] = rate
44
+ end
41
45
  end
42
46
 
43
47
  # Retrieve the rate for the given currencies. Uses +Mutex+ to synchronize data access.
@@ -54,24 +58,21 @@ class Money
54
58
  #
55
59
  # store.get_rate("USD", "CAD") #=> 1.24515
56
60
  def get_rate(currency_iso_from, currency_iso_to)
57
- transaction { index[rate_key_for(currency_iso_from, currency_iso_to)] }
61
+ @guard.synchronize do
62
+ @rates[rate_key_for(currency_iso_from, currency_iso_to)]
63
+ end
58
64
  end
59
65
 
60
66
  def marshal_dump
61
- [self.class, options, index]
67
+ @guard.synchronize do
68
+ return [self.class, @options, @rates.dup]
69
+ end
62
70
  end
63
71
 
64
72
  # Wraps block execution in a thread-safe transaction
65
73
  def transaction(&block)
66
- if @in_transaction || options[:without_mutex]
67
- block.call self
68
- else
69
- @mutex.synchronize do
70
- @in_transaction = true
71
- result = block.call
72
- @in_transaction = false
73
- result
74
- end
74
+ @guard.synchronize do
75
+ yield
75
76
  end
76
77
  end
77
78
 
@@ -88,20 +89,18 @@ class Money
88
89
  # puts [iso_from, iso_to, rate].join
89
90
  # end
90
91
  def each_rate(&block)
91
- enum = Enumerator.new do |yielder|
92
- index.each do |key, rate|
92
+ return to_enum(:each_rate) unless block_given?
93
+
94
+ @guard.synchronize do
95
+ @rates.each do |key, rate|
93
96
  iso_from, iso_to = key.split(INDEX_KEY_SEPARATOR)
94
- yielder.yield iso_from, iso_to, rate
97
+ yield iso_from, iso_to, rate
95
98
  end
96
99
  end
97
-
98
- block_given? ? enum.each(&block) : enum
99
100
  end
100
101
 
101
102
  private
102
103
 
103
- attr_reader :index, :options
104
-
105
104
  # Return the rate hashkey for the given currencies.
106
105
  #
107
106
  # @param [String] currency_iso_from The currency to exchange from.
@@ -1,3 +1,3 @@
1
1
  class Money
2
- VERSION = '6.13.4'
2
+ VERSION = '6.13.5'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: money
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.13.4
4
+ version: 6.13.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shane Emmons
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-06-10 00:00:00.000000000 Z
12
+ date: 2019-12-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: i18n
@@ -159,8 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
159
159
  - !ruby/object:Gem::Version
160
160
  version: '0'
161
161
  requirements: []
162
- rubyforge_project:
163
- rubygems_version: 2.6.8
162
+ rubygems_version: 3.0.3
164
163
  signing_key:
165
164
  specification_version: 4
166
165
  summary: A Ruby Library for dealing with money and currency conversion.