money 6.13.5 → 6.14.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +31 -2
- data/README.md +28 -6
- data/config/currency_backwards_compatible.json +4 -0
- data/config/currency_iso.json +101 -8
- data/config/currency_non_iso.json +1 -0
- data/lib/money/bank/variable_exchange.rb +12 -6
- data/lib/money/currency.rb +8 -3
- data/lib/money/money.rb +94 -46
- data/lib/money/money/allocation.rb +10 -4
- data/lib/money/money/arithmetic.rb +18 -13
- data/lib/money/money/formatter.rb +1 -1
- data/lib/money/money/formatting_rules.rb +2 -0
- data/lib/money/rates_store/memory.rb +12 -10
- data/lib/money/version.rb +1 -1
- metadata +3 -3
@@ -347,7 +347,7 @@ class Money
|
|
347
347
|
end
|
348
348
|
|
349
349
|
def format_decimal_part(value)
|
350
|
-
return nil if currency.decimal_places == 0 && !Money.
|
350
|
+
return nil if currency.decimal_places == 0 && !Money.default_infinite_precision
|
351
351
|
return nil if rules[:no_cents]
|
352
352
|
return nil if rules[:no_cents_if_whole] && value.to_i == 0
|
353
353
|
|
@@ -19,7 +19,7 @@ class Money
|
|
19
19
|
#
|
20
20
|
# @param [Hash] opts Optional store options.
|
21
21
|
# @option opts [Boolean] :without_mutex disables the usage of a mutex
|
22
|
-
# @param [Hash]
|
22
|
+
# @param [Hash] rates Optional initial exchange rate data.
|
23
23
|
def initialize(opts = {}, rates = {})
|
24
24
|
@rates = rates
|
25
25
|
@options = opts
|
@@ -39,8 +39,8 @@ class Money
|
|
39
39
|
# store.add_rate("USD", "CAD", 1.24515)
|
40
40
|
# store.add_rate("CAD", "USD", 0.803115)
|
41
41
|
def add_rate(currency_iso_from, currency_iso_to, rate)
|
42
|
-
|
43
|
-
|
42
|
+
guard.synchronize do
|
43
|
+
rates[rate_key_for(currency_iso_from, currency_iso_to)] = rate
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
@@ -58,20 +58,20 @@ class Money
|
|
58
58
|
#
|
59
59
|
# store.get_rate("USD", "CAD") #=> 1.24515
|
60
60
|
def get_rate(currency_iso_from, currency_iso_to)
|
61
|
-
|
62
|
-
|
61
|
+
guard.synchronize do
|
62
|
+
rates[rate_key_for(currency_iso_from, currency_iso_to)]
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
66
|
def marshal_dump
|
67
|
-
|
68
|
-
return [self.class,
|
67
|
+
guard.synchronize do
|
68
|
+
return [self.class, options, rates.dup]
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
72
|
# Wraps block execution in a thread-safe transaction
|
73
73
|
def transaction(&block)
|
74
|
-
|
74
|
+
guard.synchronize do
|
75
75
|
yield
|
76
76
|
end
|
77
77
|
end
|
@@ -91,8 +91,8 @@ class Money
|
|
91
91
|
def each_rate(&block)
|
92
92
|
return to_enum(:each_rate) unless block_given?
|
93
93
|
|
94
|
-
|
95
|
-
|
94
|
+
guard.synchronize do
|
95
|
+
rates.each do |key, rate|
|
96
96
|
iso_from, iso_to = key.split(INDEX_KEY_SEPARATOR)
|
97
97
|
yield iso_from, iso_to, rate
|
98
98
|
end
|
@@ -101,6 +101,8 @@ class Money
|
|
101
101
|
|
102
102
|
private
|
103
103
|
|
104
|
+
attr_reader :rates, :options, :guard
|
105
|
+
|
104
106
|
# Return the rate hashkey for the given currencies.
|
105
107
|
#
|
106
108
|
# @param [String] currency_iso_from The currency to exchange from.
|
data/lib/money/version.rb
CHANGED
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.
|
4
|
+
version: 6.14.1
|
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:
|
12
|
+
date: 2021-02-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: i18n
|
@@ -159,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
159
159
|
- !ruby/object:Gem::Version
|
160
160
|
version: '0'
|
161
161
|
requirements: []
|
162
|
-
rubygems_version: 3.
|
162
|
+
rubygems_version: 3.1.2
|
163
163
|
signing_key:
|
164
164
|
specification_version: 4
|
165
165
|
summary: A Ruby Library for dealing with money and currency conversion.
|