eu_central_bank 1.4.2 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +6 -0
- data/lib/eu_central_bank.rb +5 -5
- data/lib/money/rates_store/store_with_historical_data_support.rb +10 -27
- metadata +13 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 52d1fe9c87277a5ff6fdb243688949f5159686690a1bab6d8210ff0c643381da
|
4
|
+
data.tar.gz: 8cc1b167c31e16ae87a4d89f62f298a5a05639f10611c5f5064bae72029818a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a026554544da7e040565e6daa9cca1aad9e35be6d041511dcf16fb8d4cae90e6d02430a5940f21464675b95a70a4a52e1c7eb09dfffa9dabb213a79ab5bc3938
|
7
|
+
data.tar.gz: c913cbcd6c2c0c8c247fba9eb582b57600ad75acf932b1fa5817bc81b260c2135193c876ed16d51a08d8150c2c464870b8a0a7f8f5ff48765bebd59a1879282f
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# eu_central_bank changelog
|
2
2
|
|
3
|
+
## 1.5.0 (Dec 7 2019)
|
4
|
+
|
5
|
+
* Fix issue with money gem incompatibility
|
6
|
+
* Fix thread safety of the default rates store
|
7
|
+
* Bump money dependency to >= 6.13.6
|
8
|
+
|
3
9
|
## 1.4.2 (Feb 2 2019)
|
4
10
|
|
5
11
|
* Fix issue with importing exported rates
|
data/lib/eu_central_bank.rb
CHANGED
@@ -15,7 +15,7 @@ class EuCentralBank < Money::Bank::VariableExchange
|
|
15
15
|
attr_accessor :historical_rates_updated_at
|
16
16
|
|
17
17
|
SERIALIZER_DATE_SEPARATOR = '_AT_'
|
18
|
-
|
18
|
+
DECIMAL_PRECISION = 5
|
19
19
|
CURRENCIES = %w(USD JPY BGN CZK DKK GBP HUF ILS ISK PLN RON SEK CHF NOK HRK RUB TRY AUD BRL CAD CNY HKD IDR INR KRW MXN MYR NZD PHP SGD THB ZAR).map(&:freeze).freeze
|
20
20
|
ECB_RATES_URL = 'https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml'.freeze
|
21
21
|
ECB_90_DAY_URL = 'https://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist-90d.xml'.freeze
|
@@ -146,7 +146,7 @@ class EuCentralBank < Money::Bank::VariableExchange
|
|
146
146
|
from, to = key.split(SERIALIZER_SEPARATOR)
|
147
147
|
to, date = to.split(SERIALIZER_DATE_SEPARATOR)
|
148
148
|
|
149
|
-
store.add_rate from, to, BigDecimal(rate), date
|
149
|
+
store.add_rate from, to, BigDecimal(rate, DECIMAL_PRECISION), date
|
150
150
|
end
|
151
151
|
end
|
152
152
|
|
@@ -178,7 +178,7 @@ class EuCentralBank < Money::Bank::VariableExchange
|
|
178
178
|
|
179
179
|
store.transaction true do
|
180
180
|
rates.each do |exchange_rate|
|
181
|
-
rate = BigDecimal(exchange_rate.attribute("rate").value)
|
181
|
+
rate = BigDecimal(exchange_rate.attribute("rate").value, DECIMAL_PRECISION)
|
182
182
|
currency = exchange_rate.attribute("currency").value
|
183
183
|
set_rate("EUR", currency, rate)
|
184
184
|
end
|
@@ -196,7 +196,7 @@ class EuCentralBank < Money::Bank::VariableExchange
|
|
196
196
|
|
197
197
|
store.transaction true do
|
198
198
|
rates.each do |exchange_rate|
|
199
|
-
rate = BigDecimal(exchange_rate.attribute("rate").value)
|
199
|
+
rate = BigDecimal(exchange_rate.attribute("rate").value, DECIMAL_PRECISION)
|
200
200
|
currency = exchange_rate.attribute("currency").value
|
201
201
|
date = exchange_rate.parent.attribute("time").value
|
202
202
|
set_rate("EUR", currency, rate, date)
|
@@ -214,7 +214,7 @@ class EuCentralBank < Money::Bank::VariableExchange
|
|
214
214
|
def calculate_exchange(from, to_currency, rate)
|
215
215
|
to_currency_money = Money::Currency.wrap(to_currency).subunit_to_unit
|
216
216
|
from_currency_money = from.currency.subunit_to_unit
|
217
|
-
decimal_money = BigDecimal(to_currency_money) / BigDecimal(from_currency_money)
|
217
|
+
decimal_money = BigDecimal(to_currency_money, DECIMAL_PRECISION) / BigDecimal(from_currency_money, DECIMAL_PRECISION)
|
218
218
|
money = (decimal_money * from.cents * rate).round
|
219
219
|
Money.new(money, to_currency)
|
220
220
|
end
|
@@ -3,33 +3,16 @@ module Money::RatesStore
|
|
3
3
|
INDEX_DATE_SEPARATOR = '_AT_'.freeze
|
4
4
|
|
5
5
|
def add_rate(currency_iso_from, currency_iso_to, rate, date = nil)
|
6
|
-
transaction {
|
6
|
+
transaction { rates[rate_key_for(currency_iso_from, currency_iso_to, date)] = rate }
|
7
7
|
end
|
8
8
|
|
9
9
|
def get_rate(currency_iso_from, currency_iso_to, date = nil)
|
10
|
-
transaction {
|
10
|
+
transaction { rates[rate_key_for(currency_iso_from, currency_iso_to, date)] }
|
11
11
|
end
|
12
12
|
|
13
13
|
# Wraps block execution in a thread-safe transaction
|
14
|
-
def transaction(
|
15
|
-
|
16
|
-
if @mutex.respond_to?(:owned?)
|
17
|
-
force_sync = false if @mutex.locked? && @mutex.owned?
|
18
|
-
else
|
19
|
-
# If we allowed this in Ruby 1.9.3, it might possibly cause recursive
|
20
|
-
# locking within the same thread.
|
21
|
-
force_sync = false
|
22
|
-
end
|
23
|
-
if !force_sync && (@in_transaction || options[:without_mutex])
|
24
|
-
block.call self
|
25
|
-
else
|
26
|
-
@mutex.synchronize do
|
27
|
-
@in_transaction = true
|
28
|
-
result = block.call
|
29
|
-
@in_transaction = false
|
30
|
-
result
|
31
|
-
end
|
32
|
-
end
|
14
|
+
def transaction(_force_sync = false, &block)
|
15
|
+
super &block
|
33
16
|
end
|
34
17
|
|
35
18
|
# Iterate over rate tuples (iso_from, iso_to, rate)
|
@@ -47,7 +30,7 @@ module Money::RatesStore
|
|
47
30
|
# end
|
48
31
|
def each_rate(&block)
|
49
32
|
enum = Enumerator.new do |yielder|
|
50
|
-
|
33
|
+
rates.each do |key, rate|
|
51
34
|
iso_from, iso_to = key.split(Memory::INDEX_KEY_SEPARATOR)
|
52
35
|
iso_to, date = iso_to.split(INDEX_DATE_SEPARATOR)
|
53
36
|
date = Date.parse(date) if date
|
@@ -60,10 +43,10 @@ module Money::RatesStore
|
|
60
43
|
|
61
44
|
private
|
62
45
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
46
|
+
def rate_key_for(currency_iso_from, currency_iso_to, date = nil)
|
47
|
+
key = [currency_iso_from, currency_iso_to].join(Memory::INDEX_KEY_SEPARATOR)
|
48
|
+
key = [key, date.to_s].join(INDEX_DATE_SEPARATOR) if date
|
49
|
+
key.upcase
|
50
|
+
end
|
68
51
|
end
|
69
52
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eu_central_bank
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shane Emmons
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
19
|
+
version: '1.9'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1.
|
26
|
+
version: '1.9'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: money
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -31,6 +31,9 @@ dependencies:
|
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '6.13'
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 6.13.6
|
34
37
|
type: :runtime
|
35
38
|
prerelease: false
|
36
39
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -38,6 +41,9 @@ dependencies:
|
|
38
41
|
- - "~>"
|
39
42
|
- !ruby/object:Gem::Version
|
40
43
|
version: '6.13'
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 6.13.6
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
48
|
name: rspec
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,7 +72,8 @@ files:
|
|
66
72
|
- lib/eu_central_bank.rb
|
67
73
|
- lib/money/rates_store/store_with_historical_data_support.rb
|
68
74
|
homepage: https://github.com/RubyMoney/eu_central_bank
|
69
|
-
licenses:
|
75
|
+
licenses:
|
76
|
+
- MIT
|
70
77
|
metadata: {}
|
71
78
|
post_install_message:
|
72
79
|
rdoc_options: []
|
@@ -83,8 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
90
|
- !ruby/object:Gem::Version
|
84
91
|
version: '0'
|
85
92
|
requirements: []
|
86
|
-
|
87
|
-
rubygems_version: 2.6.8
|
93
|
+
rubygems_version: 3.0.3
|
88
94
|
signing_key:
|
89
95
|
specification_version: 4
|
90
96
|
summary: Calculates exchange rates based on rates from european central bank. Money
|