active_currency 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -6
- data/lib/active_currency.rb +1 -1
- data/lib/active_currency/add_rates.rb +4 -0
- data/lib/active_currency/bank.rb +9 -0
- data/lib/active_currency/version.rb +1 -1
- metadata +3 -4
- data/db/migrate/20180914064834_add_rates.rb +0 -7
- data/lib/active_currency/memory_rate_store.rb +0 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b1fe215e9c8bb75f210ec88c1e3e301f0c86fda7
|
4
|
+
data.tar.gz: 29a6441e018cdf3b224be0a5d5369d2069cc26fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 728585d0085673bd3de09001cf83fcaab57cf03003e16c5b31a42e51a8a99fcb498f51aa25250c2a3eabf1ea335620d0d3e23cd177ad7abd3f91a970b635c278
|
7
|
+
data.tar.gz: 0b7de9fea58eb52cbb375346ab47f08b4251c33d42a853dce72a27505c64bcab68afcb472a0f5aeaeffc2a6d7b3bd6d6c818fd837c590e9780b9852da66c17eb
|
data/README.md
CHANGED
@@ -23,10 +23,10 @@ To fetch the rates, it uses the [eu_central_bank] gem.
|
|
23
23
|
## Usage
|
24
24
|
|
25
25
|
Store the current rate regularly by calling in a scheduled job (using something
|
26
|
-
like `sidekiq-scheduler` or `whenever`):
|
26
|
+
like `sidekiq-scheduler` or `whenever`) with the currencies you want to store:
|
27
27
|
|
28
28
|
```rb
|
29
|
-
ActiveCurrency::AddRates.
|
29
|
+
ActiveCurrency::AddRates.call(%w[EUR USD])
|
30
30
|
```
|
31
31
|
|
32
32
|
You can then exchange money by using the Money gem:
|
@@ -57,8 +57,7 @@ And in `config/initializers/money.rb`:
|
|
57
57
|
|
58
58
|
```rb
|
59
59
|
MoneyRails.configure do |config|
|
60
|
-
config.default_bank =
|
61
|
-
Money::Bank::VariableExchange.new(ActiveCurrency::RateStore.new)
|
60
|
+
config.default_bank = ActiveCurrency::Bank.new
|
62
61
|
end
|
63
62
|
```
|
64
63
|
|
@@ -70,11 +69,11 @@ the currency rates and fill it for the first time.
|
|
70
69
|
In your app test suite you may not want to have to fill your database to be
|
71
70
|
able to exchange currencies.
|
72
71
|
|
73
|
-
For that, you
|
72
|
+
For that, you should use a fake rate store in `config/initializers/money.rb`:
|
74
73
|
|
75
74
|
```rb
|
76
75
|
if Rails.env.test?
|
77
|
-
rate_store =
|
76
|
+
rate_store = Money::RatesStore::Memory.new.tap do |store|
|
78
77
|
store.add_rate('USD', 'EUR', 0.5)
|
79
78
|
store.add_rate('EUR', 'USD', 1.5)
|
80
79
|
end
|
data/lib/active_currency.rb
CHANGED
@@ -8,8 +8,8 @@ require 'active_currency/engine'
|
|
8
8
|
require 'active_currency/database_store'
|
9
9
|
require 'active_currency/cacheable_store'
|
10
10
|
require 'active_currency/rate_store'
|
11
|
-
require 'active_currency/memory_rate_store'
|
12
11
|
require 'active_currency/add_rates'
|
12
|
+
require 'active_currency/bank'
|
13
13
|
|
14
14
|
module ActiveCurrency
|
15
15
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_currency
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sunny Ripert
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -133,13 +133,12 @@ files:
|
|
133
133
|
- README.md
|
134
134
|
- app/models/active_currency/rate.rb
|
135
135
|
- db/migrate/20180911202100_create_active_currency_rates.rb
|
136
|
-
- db/migrate/20180914064834_add_rates.rb
|
137
136
|
- lib/active_currency.rb
|
138
137
|
- lib/active_currency/add_rates.rb
|
138
|
+
- lib/active_currency/bank.rb
|
139
139
|
- lib/active_currency/cacheable_store.rb
|
140
140
|
- lib/active_currency/database_store.rb
|
141
141
|
- lib/active_currency/engine.rb
|
142
|
-
- lib/active_currency/memory_rate_store.rb
|
143
142
|
- lib/active_currency/migration.rb
|
144
143
|
- lib/active_currency/rate_store.rb
|
145
144
|
- lib/active_currency/version.rb
|
@@ -1,20 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module ActiveCurrency
|
4
|
-
class MemoryRateStore < Money::RatesStore::Memory
|
5
|
-
def initialize(**)
|
6
|
-
@currencies = Set.new
|
7
|
-
super
|
8
|
-
end
|
9
|
-
|
10
|
-
def currencies
|
11
|
-
@currencies.to_a
|
12
|
-
end
|
13
|
-
|
14
|
-
def add_rate(from, to, value)
|
15
|
-
@currencies << from
|
16
|
-
@currencies << to
|
17
|
-
super
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|