eu_central_bank 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +2 -1
- data/lib/eu_central_bank.rb +16 -0
- data/lib/money/rates_store/eu_central_bank_historical_data_support.rb +20 -21
- metadata +17 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d5f8b86e4c137232c18a652e039693e6675b688
|
4
|
+
data.tar.gz: 6016b5f506d4ffc693afee6000c40d6e6f4e0fff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94afc27fbe11e777cc59b319833354192e81a1df0622e6dd3dc680c4cbea6d0c079950447835f6f991595708723235b535d3d4beb3c350dd3e357634ea9a597a
|
7
|
+
data.tar.gz: be12ff053f29df84bee8cae7b6ddb067cfcdbcec2fec011c534bf433bfe2cf6085fb9618b77930ab1e0f7c986d1fb84a37b8fb3b7a2864c5547e9d7d8dc40da1
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# eu_central_bank changelog
|
2
2
|
|
3
|
+
## 1.1.0 (Jan 19 2017)
|
4
|
+
|
5
|
+
* Added support for ruby 2.3.0 and 2.4.0
|
6
|
+
* Fixed ruby warnings
|
7
|
+
* Fixed thread safety issue
|
8
|
+
* Fixed issue with historical rates
|
9
|
+
* Added exception for currencies not in the list
|
10
|
+
|
3
11
|
## 1.0.1 (May 20 2016)
|
4
12
|
|
5
13
|
* Fixed compatibility with recent Money gem
|
data/README.md
CHANGED
@@ -22,6 +22,7 @@ gem install eu_central_bank
|
|
22
22
|
With the gem, you do not need to manually add exchange rates. Calling update_rates will download the rates from the European Central Bank. The API is the same as the money gem. Feel free to use Money objects with the bank.
|
23
23
|
|
24
24
|
``` ruby
|
25
|
+
require 'eu_central_bank'
|
25
26
|
eu_bank = EuCentralBank.new
|
26
27
|
Money.default_bank = eu_bank
|
27
28
|
money1 = Money.new(10)
|
@@ -70,4 +71,4 @@ eu_bank.exchange_with(Money.new(100, "CAD"), "USD") # Money.new(80, "USD")
|
|
70
71
|
|
71
72
|
## Copyright
|
72
73
|
|
73
|
-
Copyright (c) 2010-
|
74
|
+
Copyright (c) 2010-2016 RubyMoney. See LICENSE for details.
|
data/lib/eu_central_bank.rb
CHANGED
@@ -5,6 +5,8 @@ require 'money/rates_store/eu_central_bank_historical_data_support'
|
|
5
5
|
|
6
6
|
class InvalidCache < StandardError ; end
|
7
7
|
|
8
|
+
class CurrencyUnavailable < StandardError; end
|
9
|
+
|
8
10
|
class EuCentralBank < Money::Bank::VariableExchange
|
9
11
|
|
10
12
|
attr_accessor :last_updated
|
@@ -21,6 +23,7 @@ class EuCentralBank < Money::Bank::VariableExchange
|
|
21
23
|
def initialize(*)
|
22
24
|
super
|
23
25
|
@store.extend Money::RatesStore::EuCentralBankHistoricalDataSupport
|
26
|
+
@currency_string = nil
|
24
27
|
end
|
25
28
|
|
26
29
|
def update_rates(cache=nil)
|
@@ -67,10 +70,16 @@ class EuCentralBank < Money::Bank::VariableExchange
|
|
67
70
|
end
|
68
71
|
|
69
72
|
def get_rate(from, to, date = nil)
|
73
|
+
return 1 if from == to
|
74
|
+
|
75
|
+
check_currency_available(from)
|
76
|
+
check_currency_available(to)
|
77
|
+
|
70
78
|
if date.is_a?(Hash)
|
71
79
|
# Backwards compatibility for the opts hash
|
72
80
|
date = date[:date]
|
73
81
|
end
|
82
|
+
|
74
83
|
store.get_rate(::Money::Currency.wrap(from).iso_code, ::Money::Currency.wrap(to).iso_code, date)
|
75
84
|
end
|
76
85
|
|
@@ -136,6 +145,13 @@ class EuCentralBank < Money::Bank::VariableExchange
|
|
136
145
|
self
|
137
146
|
end
|
138
147
|
|
148
|
+
def check_currency_available(currency)
|
149
|
+
currency_string = currency.to_s
|
150
|
+
return true if currency_string == "EUR"
|
151
|
+
return true if CURRENCIES.include?(currency_string)
|
152
|
+
raise CurrencyUnavailable, "No rates available for #{@currency_string}"
|
153
|
+
end
|
154
|
+
|
139
155
|
protected
|
140
156
|
|
141
157
|
def doc(cache, url=ECB_RATES_URL)
|
@@ -10,27 +10,27 @@ module Money::RatesStore
|
|
10
10
|
transaction { index[rate_key_for(currency_iso_from, currency_iso_to, date)] }
|
11
11
|
end
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
13
|
+
# Wraps block execution in a thread-safe transaction
|
14
|
+
def transaction(force_sync = false, &block)
|
15
|
+
# Ruby 1.9.3 does not support @mutex.owned?
|
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
|
31
32
|
end
|
32
33
|
end
|
33
|
-
end
|
34
34
|
|
35
35
|
# Iterate over rate tuples (iso_from, iso_to, rate)
|
36
36
|
#
|
@@ -65,6 +65,5 @@ module Money::RatesStore
|
|
65
65
|
key = [key, date.to_s].join(INDEX_DATE_SEPARATOR) if date
|
66
66
|
key.upcase
|
67
67
|
end
|
68
|
-
|
69
68
|
end
|
70
|
-
end
|
69
|
+
end
|
metadata
CHANGED
@@ -1,57 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eu_central_bank
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.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:
|
11
|
+
date: 2017-01-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 1.6.3
|
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
26
|
version: 1.6.3
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: money
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 6.
|
33
|
+
version: 6.8.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 6.
|
40
|
+
version: 6.8.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ~>
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 3.
|
47
|
+
version: 3.5.0
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 3.
|
54
|
+
version: 3.5.0
|
55
55
|
description: This gem reads exchange rates from the european central bank website.
|
56
56
|
It uses it to calculates exchange rates. It is compatible with the money gem
|
57
57
|
email:
|
@@ -60,11 +60,11 @@ executables: []
|
|
60
60
|
extensions: []
|
61
61
|
extra_rdoc_files: []
|
62
62
|
files:
|
63
|
+
- lib/eu_central_bank.rb
|
64
|
+
- lib/money/rates_store/eu_central_bank_historical_data_support.rb
|
63
65
|
- CHANGELOG.md
|
64
66
|
- LICENSE
|
65
67
|
- README.md
|
66
|
-
- lib/eu_central_bank.rb
|
67
|
-
- lib/money/rates_store/eu_central_bank_historical_data_support.rb
|
68
68
|
homepage: https://github.com/RubyMoney/eu_central_bank
|
69
69
|
licenses: []
|
70
70
|
metadata: {}
|
@@ -74,17 +74,17 @@ require_paths:
|
|
74
74
|
- lib
|
75
75
|
required_ruby_version: !ruby/object:Gem::Requirement
|
76
76
|
requirements:
|
77
|
-
- -
|
77
|
+
- - '>='
|
78
78
|
- !ruby/object:Gem::Version
|
79
79
|
version: '0'
|
80
80
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
81
|
requirements:
|
82
|
-
- -
|
82
|
+
- - '>='
|
83
83
|
- !ruby/object:Gem::Version
|
84
84
|
version: '0'
|
85
85
|
requirements: []
|
86
86
|
rubyforge_project:
|
87
|
-
rubygems_version: 2.
|
87
|
+
rubygems_version: 2.0.14.1
|
88
88
|
signing_key:
|
89
89
|
specification_version: 4
|
90
90
|
summary: Calculates exchange rates based on rates from european central bank. Money
|