danconia 0.3.0 → 0.3.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d059c26cfe3dfb8fdd9da2a14f14d4207f49d39e57a8ac11624e4069f1612632
4
- data.tar.gz: 2a7022742e0c9fdb318d57bf916828c18eab1c040aa7ec571912e243aef14028
3
+ metadata.gz: fa3a0d9c0c4c51c0e1c1ad8c229ecc6ddf2c075d19deb49c80420794eba6ae62
4
+ data.tar.gz: f754a58e13cb947945a77e5629bbb2cada05b88ba50afa67a532d98a7cbe1b3a
5
5
  SHA512:
6
- metadata.gz: 6c3ad4d5a0d58ca3fb6be34d557dfec5ef0578adf627edc2de3c7cee8b68eab84aafcebbf58c59e5622974dc8b2b7e609dd58e1d7dcf502eacd2090610ed7b4a
7
- data.tar.gz: 439f6bb772fdef77bc221c6e4167a053b6366ff39fe8b20c3b6f81393901bc7c8364c1c326e357c0d2160ecd7bb50734cbdf1ae37eeb169bd2232b93e13e5181
6
+ metadata.gz: 85d9f69230479cdff0c7ae0b9dbea96b75de1e5dff9768ff7030e511e37e09f01242a18fc80f83eee57ddf89045c55c2fc84349d0ac22f41aeb05ae0ccc73734
7
+ data.tar.gz: 59639da6306a1db105d09a2d8b1762948a383e727cafaac66718e0f0ddb08a7a572ddcac1ffb151f1eda7cdbe73e766a3d000a8fed4764949102311e782926f3
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- danconia (0.3.0)
4
+ danconia (0.3.1)
5
5
  activesupport (>= 4.0)
6
6
 
7
7
  GEM
@@ -2,6 +2,7 @@ require 'date'
2
2
 
3
3
  require 'active_support'
4
4
  require 'active_support/core_ext/object/blank'
5
+ require 'active_support/core_ext/hash/reverse_merge'
5
6
 
6
7
  require 'danconia/version'
7
8
  require 'danconia/config'
@@ -1,9 +1,12 @@
1
1
  require 'bigdecimal'
2
2
  require 'danconia/errors/exchange_rate_not_found'
3
+ require 'danconia/serializable'
3
4
 
4
5
  module Danconia
5
6
  class Money
6
7
  include Comparable
8
+ include Serializable
9
+
7
10
  attr_reader :amount, :currency, :decimals
8
11
 
9
12
  def initialize(amount, currency_code = nil, decimals: 2, exchange_opts: {})
@@ -67,10 +70,6 @@ module Danconia
67
70
  (self * 100).round
68
71
  end
69
72
 
70
- def as_json *args
71
- amount.as_json *args
72
- end
73
-
74
73
  def default_currency?
75
74
  currency.code == Danconia.config.default_currency
76
75
  end
@@ -83,8 +82,8 @@ module Danconia
83
82
  end
84
83
  end
85
84
 
86
- def respond_to? method, *args
87
- super or @amount.respond_to?(method, *args)
85
+ def respond_to_missing? method, *args
86
+ @amount.respond_to?(method, *args) || super
88
87
  end
89
88
 
90
89
  private
@@ -0,0 +1,17 @@
1
+ module Danconia
2
+ module Serializable
3
+ def marshal_dump
4
+ {amount: @amount, currency: @currency.code, decimals: @decimals}
5
+ end
6
+
7
+ def marshal_load serialized_money
8
+ @amount = serialized_money[:amount]
9
+ @currency = Currency.find(serialized_money[:currency])
10
+ @decimals = serialized_money[:decimals]
11
+ end
12
+
13
+ def as_json _options = {}
14
+ {amount: @amount, currency: @currency.code}
15
+ end
16
+ end
17
+ end
@@ -1,3 +1,3 @@
1
1
  module Danconia
2
- VERSION = '0.3.0'
2
+ VERSION = '0.3.1'
3
3
  end
@@ -31,6 +31,22 @@ module Danconia
31
31
  File.read("#{__dir__}/fixtures/bna/#{file}")
32
32
  end
33
33
  end
34
+
35
+ context 'rates' do
36
+ it 'pass the params to the store and converts the array of rates back to hash' do
37
+ store = double('store')
38
+ expect(store).to receive(:rates)
39
+ .with(rate_type: 'billetes', date: nil)
40
+ .and_return([{pair: 'USDARS', rate: 3}])
41
+
42
+ exchange = BNA.new(store: store)
43
+ expect(exchange.rates(rate_type: 'billetes')).to eq 'USDARS' => 3
44
+ end
45
+
46
+ it 'rate_type is required' do
47
+ expect { BNA.new.rates }.to raise_error ArgumentError
48
+ end
49
+ end
34
50
  end
35
51
  end
36
52
  end
@@ -213,12 +213,6 @@ module Danconia
213
213
  end
214
214
  end
215
215
 
216
- context 'to_json' do
217
- it 'should delegate to the amount' do
218
- expect(Money(1).to_json).to eq '"1.0"'
219
- end
220
- end
221
-
222
216
  def fake_exchange args = {}
223
217
  double 'Danconia::Exchange', args.reverse_merge(rate: nil)
224
218
  end
@@ -0,0 +1,16 @@
1
+ module Danconia
2
+ describe Serializable do
3
+ context 'marshalling' do
4
+ it 'money objects support dump and load' do
5
+ expect(Marshal.load(Marshal.dump(Money(5, 'USD')))).to eq Money(5, 'USD')
6
+ expect(Marshal.load(Marshal.dump(Money(3.2, 'ARS')))).to eq Money(3.2, 'ARS')
7
+ end
8
+ end
9
+
10
+ context 'to_json' do
11
+ it 'should delegate to the amount' do
12
+ expect(Money(1).to_json).to eq %({"amount":"1.0","currency":"USD"})
13
+ end
14
+ end
15
+ end
16
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: danconia
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emmanuel Nicolau
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-03 00:00:00.000000000 Z
11
+ date: 2020-12-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -187,6 +187,7 @@ files:
187
187
  - lib/danconia/kernel.rb
188
188
  - lib/danconia/money.rb
189
189
  - lib/danconia/pair.rb
190
+ - lib/danconia/serializable.rb
190
191
  - lib/danconia/stores/active_record.rb
191
192
  - lib/danconia/stores/in_memory.rb
192
193
  - lib/danconia/test_helpers.rb
@@ -199,6 +200,7 @@ files:
199
200
  - spec/danconia/exchanges/fixtures/currency_layer/success.json
200
201
  - spec/danconia/integrations/active_record_spec.rb
201
202
  - spec/danconia/money_spec.rb
203
+ - spec/danconia/serializable_spec.rb
202
204
  - spec/danconia/stores/active_record_spec.rb
203
205
  - spec/danconia/stores/in_memory_spec.rb
204
206
  - spec/spec_helper.rb
@@ -207,7 +209,7 @@ homepage: https://github.com/eeng/danconia
207
209
  licenses:
208
210
  - MIT
209
211
  metadata: {}
210
- post_install_message:
212
+ post_install_message:
211
213
  rdoc_options: []
212
214
  require_paths:
213
215
  - lib
@@ -222,9 +224,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
222
224
  - !ruby/object:Gem::Version
223
225
  version: '0'
224
226
  requirements: []
225
- rubyforge_project:
227
+ rubyforge_project:
226
228
  rubygems_version: 2.7.3
227
- signing_key:
229
+ signing_key:
228
230
  specification_version: 4
229
231
  summary: Multi-currency money library backed by BigDecimal
230
232
  test_files:
@@ -236,6 +238,7 @@ test_files:
236
238
  - spec/danconia/exchanges/fixtures/currency_layer/success.json
237
239
  - spec/danconia/integrations/active_record_spec.rb
238
240
  - spec/danconia/money_spec.rb
241
+ - spec/danconia/serializable_spec.rb
239
242
  - spec/danconia/stores/active_record_spec.rb
240
243
  - spec/danconia/stores/in_memory_spec.rb
241
244
  - spec/spec_helper.rb