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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 56f6adecbe4588cdec72671119078133df0cb4bc
4
- data.tar.gz: 03425c4a136c196d0776d8160e8a7b9c0c4c66e6
3
+ metadata.gz: b1fe215e9c8bb75f210ec88c1e3e301f0c86fda7
4
+ data.tar.gz: 29a6441e018cdf3b224be0a5d5369d2069cc26fd
5
5
  SHA512:
6
- metadata.gz: fde85398d3c49aa68f1ed012025f443bc47a43ef5ed513670c4ce679ba4eec9c1aa460e256d1ac4125b69fb6fe8f5412536601828f5257bbc1b897933ecc7688
7
- data.tar.gz: 566f5c432f78da8151db7d5ed9ed81e83c1e6cdba28999f42a15eed930fc750f21606d9b77a8e8982b54f81ec7369cc7ff91c54c3709cc7375ce706933f8fc64
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.new(%w[EUR USD]).call
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 can in `config/initializers/money.rb`:
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 = ActiveCurrency::MemoryRateStore.new.tap do |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
@@ -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
@@ -21,6 +21,10 @@ module ActiveCurrency
21
21
  end
22
22
  end
23
23
 
24
+ def self.call(currencies)
25
+ new(currencies).call
26
+ end
27
+
24
28
  private
25
29
 
26
30
  def currencies
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveCurrency
4
+ class Bank < Money::Bank::VariableExchange
5
+ def initialize(rate_store = ActiveCurrency::RateStore.new)
6
+ super(rate_store)
7
+ end
8
+ end
9
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveCurrency
4
- VERSION = '0.4.0'
4
+ VERSION = '0.5.0'
5
5
  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.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-09-26 00:00:00.000000000 Z
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,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class AddRates < ActiveCurrency::Migration
4
- def up
5
- ActiveCurrency::AddRates.new.call
6
- end
7
- end
@@ -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