active_currency 0.2.0 → 0.3.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/README.md +3 -3
- data/app/models/active_currency/rate.rb +0 -6
- data/lib/active_currency/add_rates.rb +13 -5
- data/lib/active_currency/rate_store.rb +0 -6
- data/lib/active_currency/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d368ebfd81510032ab25fce067b42c55823cf23
|
4
|
+
data.tar.gz: 1bb534e253f5b4b480936ea3a1f7a194632f9d24
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f5cb10a9550211a5b590b85d181829a9cf72353364dfd3b63359acda79d9535d1c829c4ddb96669c76124f082bf3298d26286a17d0e181747ec19db670490bb
|
7
|
+
data.tar.gz: 9b404f2d1ce3313ecc733635f6cf0b499bcfc2cf802622aae4f9ba2bf2ac1c8d3d84f6b92e33dfb41c8eef8c1d31ce56e0035d52e91c67275720688335560738
|
data/README.md
CHANGED
@@ -26,7 +26,7 @@ Store the current rate regularly by calling in a scheduled job (using something
|
|
26
26
|
like `sidekiq-scheduler` or `whenever`):
|
27
27
|
|
28
28
|
```rb
|
29
|
-
ActiveCurrency::AddRates.new.call
|
29
|
+
ActiveCurrency::AddRates.new(%w[EUR USD]).call
|
30
30
|
```
|
31
31
|
|
32
32
|
You can then exchange money by using the Money gem:
|
@@ -57,8 +57,8 @@ And in `config/initializers/money.rb`:
|
|
57
57
|
|
58
58
|
```rb
|
59
59
|
MoneyRails.configure do |config|
|
60
|
-
|
61
|
-
|
60
|
+
config.default_bank =
|
61
|
+
Money::Bank::VariableExchange.new(ActiveCurrency::RateStore.new)
|
62
62
|
end
|
63
63
|
```
|
64
64
|
|
@@ -4,7 +4,6 @@ module ActiveCurrency
|
|
4
4
|
class Rate < ActiveRecord::Base
|
5
5
|
validates :from,
|
6
6
|
:to,
|
7
|
-
inclusion: { in: ->(_v) { Money.default_bank.store.currencies } },
|
8
7
|
presence: true
|
9
8
|
validates :value, numericality: { greater_than: 0 }
|
10
9
|
|
@@ -20,11 +19,6 @@ module ActiveCurrency
|
|
20
19
|
&.value
|
21
20
|
end
|
22
21
|
|
23
|
-
# DEPRECATED
|
24
|
-
def self.current_value_for(from, to, date = nil)
|
25
|
-
value_for(from, to, date)
|
26
|
-
end
|
27
|
-
|
28
22
|
# Scope retrocompatibility for Rails 3.2.
|
29
23
|
def self.all_scope
|
30
24
|
respond_to?(:scoped) ? scoped : all
|
@@ -3,20 +3,28 @@
|
|
3
3
|
module ActiveCurrency
|
4
4
|
# Store the latest currency rates.
|
5
5
|
class AddRates
|
6
|
-
def
|
7
|
-
currencies =
|
8
|
-
|
6
|
+
def initialize(currencies)
|
7
|
+
@currencies = currencies
|
8
|
+
end
|
9
9
|
|
10
|
+
def call
|
10
11
|
bank = EuCentralBank.new
|
11
12
|
bank.update_rates
|
12
13
|
|
13
14
|
from = 'EUR'
|
14
|
-
currencies.each do |to|
|
15
|
-
|
15
|
+
currencies.map(&:to_s).each do |to|
|
16
|
+
next if to == from
|
16
17
|
|
18
|
+
rate = bank.get_rate(from, to)
|
17
19
|
Money.add_rate(from, to, rate)
|
18
20
|
Money.add_rate(to, from, 1 / rate)
|
19
21
|
end
|
20
22
|
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def currencies
|
27
|
+
@currencies.map(&:to_s).map(&:upcase)
|
28
|
+
end
|
21
29
|
end
|
22
30
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_currency
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sunny Ripert
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 1.3.1
|
48
48
|
type: :runtime
|
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:
|
54
|
+
version: 1.3.1
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: sqlite3
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|