money 6.13.0 → 6.13.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +49 -2
- data/README.md +93 -3
- data/config/currency_backwards_compatible.json +31 -0
- data/config/currency_iso.json +18 -18
- data/lib/money/bank/variable_exchange.rb +14 -6
- data/lib/money/currency.rb +4 -4
- data/lib/money/currency/loader.rb +15 -13
- data/lib/money/locale_backend/currency.rb +11 -0
- data/lib/money/locale_backend/i18n.rb +2 -1
- data/lib/money/locale_backend/legacy.rb +2 -2
- data/lib/money/money.rb +100 -52
- data/lib/money/money/allocation.rb +8 -5
- data/lib/money/money/arithmetic.rb +20 -10
- data/lib/money/money/formatter.rb +3 -0
- data/lib/money/money/formatting_rules.rb +15 -5
- data/lib/money/money/locale_backend.rb +3 -1
- data/lib/money/rates_store/memory.rb +24 -23
- data/lib/money/version.rb +1 -1
- data/money.gemspec +4 -4
- metadata +11 -51
- data/.coveralls.yml +0 -1
- data/.gitignore +0 -23
- data/.rspec +0 -2
- data/.travis.yml +0 -32
- data/AUTHORS +0 -131
- data/CONTRIBUTING.md +0 -17
- data/Gemfile +0 -16
- data/Rakefile +0 -17
- data/spec/bank/base_spec.rb +0 -79
- data/spec/bank/single_currency_spec.rb +0 -13
- data/spec/bank/variable_exchange_spec.rb +0 -265
- data/spec/currency/heuristics_spec.rb +0 -11
- data/spec/currency/loader_spec.rb +0 -19
- data/spec/currency_spec.rb +0 -400
- data/spec/locale_backend/i18n_spec.rb +0 -62
- data/spec/locale_backend/legacy_spec.rb +0 -74
- data/spec/money/allocation_spec.rb +0 -130
- data/spec/money/arithmetic_spec.rb +0 -756
- data/spec/money/constructors_spec.rb +0 -91
- data/spec/money/formatting_spec.rb +0 -855
- data/spec/money/locale_backend_spec.rb +0 -14
- data/spec/money_spec.rb +0 -880
- data/spec/rates_store/memory_spec.rb +0 -80
- data/spec/spec_helper.rb +0 -30
- data/spec/support/shared_examples/money_examples.rb +0 -14
@@ -3,12 +3,14 @@
|
|
3
3
|
require 'money/locale_backend/errors'
|
4
4
|
require 'money/locale_backend/legacy'
|
5
5
|
require 'money/locale_backend/i18n'
|
6
|
+
require 'money/locale_backend/currency'
|
6
7
|
|
7
8
|
class Money
|
8
9
|
module LocaleBackend
|
9
10
|
BACKENDS = {
|
10
11
|
legacy: Money::LocaleBackend::Legacy,
|
11
|
-
i18n: Money::LocaleBackend::I18n
|
12
|
+
i18n: Money::LocaleBackend::I18n,
|
13
|
+
currency: Money::LocaleBackend::Currency
|
12
14
|
}.freeze
|
13
15
|
|
14
16
|
def self.find(name)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'monitor'
|
2
|
+
|
1
3
|
class Money
|
2
4
|
module RatesStore
|
3
5
|
|
@@ -17,11 +19,11 @@ class Money
|
|
17
19
|
#
|
18
20
|
# @param [Hash] opts Optional store options.
|
19
21
|
# @option opts [Boolean] :without_mutex disables the usage of a mutex
|
20
|
-
# @param [Hash]
|
21
|
-
def initialize(opts = {},
|
22
|
-
@
|
23
|
-
@
|
24
|
-
@
|
22
|
+
# @param [Hash] rates Optional initial exchange rate data.
|
23
|
+
def initialize(opts = {}, rates = {})
|
24
|
+
@rates = rates
|
25
|
+
@options = opts
|
26
|
+
@guard = Monitor.new
|
25
27
|
end
|
26
28
|
|
27
29
|
# Registers a conversion rate and returns it. Uses +Mutex+ to synchronize data access.
|
@@ -37,7 +39,9 @@ class Money
|
|
37
39
|
# store.add_rate("USD", "CAD", 1.24515)
|
38
40
|
# store.add_rate("CAD", "USD", 0.803115)
|
39
41
|
def add_rate(currency_iso_from, currency_iso_to, rate)
|
40
|
-
|
42
|
+
guard.synchronize do
|
43
|
+
rates[rate_key_for(currency_iso_from, currency_iso_to)] = rate
|
44
|
+
end
|
41
45
|
end
|
42
46
|
|
43
47
|
# Retrieve the rate for the given currencies. Uses +Mutex+ to synchronize data access.
|
@@ -54,24 +58,21 @@ class Money
|
|
54
58
|
#
|
55
59
|
# store.get_rate("USD", "CAD") #=> 1.24515
|
56
60
|
def get_rate(currency_iso_from, currency_iso_to)
|
57
|
-
|
61
|
+
guard.synchronize do
|
62
|
+
rates[rate_key_for(currency_iso_from, currency_iso_to)]
|
63
|
+
end
|
58
64
|
end
|
59
65
|
|
60
66
|
def marshal_dump
|
61
|
-
|
67
|
+
guard.synchronize do
|
68
|
+
return [self.class, options, rates.dup]
|
69
|
+
end
|
62
70
|
end
|
63
71
|
|
64
72
|
# Wraps block execution in a thread-safe transaction
|
65
73
|
def transaction(&block)
|
66
|
-
|
67
|
-
|
68
|
-
else
|
69
|
-
@mutex.synchronize do
|
70
|
-
@in_transaction = true
|
71
|
-
result = block.call
|
72
|
-
@in_transaction = false
|
73
|
-
result
|
74
|
-
end
|
74
|
+
guard.synchronize do
|
75
|
+
yield
|
75
76
|
end
|
76
77
|
end
|
77
78
|
|
@@ -88,19 +89,19 @@ class Money
|
|
88
89
|
# puts [iso_from, iso_to, rate].join
|
89
90
|
# end
|
90
91
|
def each_rate(&block)
|
91
|
-
|
92
|
-
|
92
|
+
return to_enum(:each_rate) unless block_given?
|
93
|
+
|
94
|
+
guard.synchronize do
|
95
|
+
rates.each do |key, rate|
|
93
96
|
iso_from, iso_to = key.split(INDEX_KEY_SEPARATOR)
|
94
|
-
|
97
|
+
yield iso_from, iso_to, rate
|
95
98
|
end
|
96
99
|
end
|
97
|
-
|
98
|
-
block_given? ? enum.each(&block) : enum
|
99
100
|
end
|
100
101
|
|
101
102
|
private
|
102
103
|
|
103
|
-
attr_reader :
|
104
|
+
attr_reader :rates, :options, :guard
|
104
105
|
|
105
106
|
# Return the rate hashkey for the given currencies.
|
106
107
|
#
|
data/lib/money/version.rb
CHANGED
data/money.gemspec
CHANGED
@@ -7,8 +7,8 @@ Gem::Specification.new do |s|
|
|
7
7
|
s.name = "money"
|
8
8
|
s.version = Money::VERSION
|
9
9
|
s.platform = Gem::Platform::RUBY
|
10
|
-
s.authors = [
|
11
|
-
s.email = [
|
10
|
+
s.authors = ['Shane Emmons', 'Anthony Dmitriyev']
|
11
|
+
s.email = ['shane@emmons.io', 'anthony.dmitriyev@gmail.com']
|
12
12
|
s.homepage = "https://rubymoney.github.io/money"
|
13
13
|
s.summary = "A Ruby Library for dealing with money and currency conversion."
|
14
14
|
s.description = "A Ruby Library for dealing with money and currency conversion."
|
@@ -16,13 +16,13 @@ Gem::Specification.new do |s|
|
|
16
16
|
|
17
17
|
s.add_dependency 'i18n', [">= 0.6.4", '<= 2']
|
18
18
|
|
19
|
-
s.add_development_dependency "bundler"
|
19
|
+
s.add_development_dependency "bundler"
|
20
20
|
s.add_development_dependency "rake"
|
21
21
|
s.add_development_dependency "rspec", "~> 3.4"
|
22
22
|
s.add_development_dependency "yard", "~> 0.9.11"
|
23
23
|
s.add_development_dependency "kramdown", "~> 1.1"
|
24
24
|
|
25
|
-
s.files = `git ls-files`.split(
|
25
|
+
s.files = `git ls-files -z -- config/* lib/* CHANGELOG.md LICENSE money.gemspec README.md`.split("\x0")
|
26
26
|
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
27
27
|
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
28
28
|
s.require_paths = ["lib"]
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: money
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.13.
|
4
|
+
version: 6.13.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shane Emmons
|
8
|
+
- Anthony Dmitriyev
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2020-07-04 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: i18n
|
@@ -34,16 +35,16 @@ dependencies:
|
|
34
35
|
name: bundler
|
35
36
|
requirement: !ruby/object:Gem::Requirement
|
36
37
|
requirements:
|
37
|
-
- - "
|
38
|
+
- - ">="
|
38
39
|
- !ruby/object:Gem::Version
|
39
|
-
version: '
|
40
|
+
version: '0'
|
40
41
|
type: :development
|
41
42
|
prerelease: false
|
42
43
|
version_requirements: !ruby/object:Gem::Requirement
|
43
44
|
requirements:
|
44
|
-
- - "
|
45
|
+
- - ">="
|
45
46
|
- !ruby/object:Gem::Version
|
46
|
-
version: '
|
47
|
+
version: '0'
|
47
48
|
- !ruby/object:Gem::Dependency
|
48
49
|
name: rake
|
49
50
|
requirement: !ruby/object:Gem::Requirement
|
@@ -103,21 +104,14 @@ dependencies:
|
|
103
104
|
description: A Ruby Library for dealing with money and currency conversion.
|
104
105
|
email:
|
105
106
|
- shane@emmons.io
|
107
|
+
- anthony.dmitriyev@gmail.com
|
106
108
|
executables: []
|
107
109
|
extensions: []
|
108
110
|
extra_rdoc_files: []
|
109
111
|
files:
|
110
|
-
- ".coveralls.yml"
|
111
|
-
- ".gitignore"
|
112
|
-
- ".rspec"
|
113
|
-
- ".travis.yml"
|
114
|
-
- AUTHORS
|
115
112
|
- CHANGELOG.md
|
116
|
-
- CONTRIBUTING.md
|
117
|
-
- Gemfile
|
118
113
|
- LICENSE
|
119
114
|
- README.md
|
120
|
-
- Rakefile
|
121
115
|
- config/currency_backwards_compatible.json
|
122
116
|
- config/currency_iso.json
|
123
117
|
- config/currency_non_iso.json
|
@@ -129,6 +123,7 @@ files:
|
|
129
123
|
- lib/money/currency/heuristics.rb
|
130
124
|
- lib/money/currency/loader.rb
|
131
125
|
- lib/money/locale_backend/base.rb
|
126
|
+
- lib/money/locale_backend/currency.rb
|
132
127
|
- lib/money/locale_backend/errors.rb
|
133
128
|
- lib/money/locale_backend/i18n.rb
|
134
129
|
- lib/money/locale_backend/legacy.rb
|
@@ -142,23 +137,6 @@ files:
|
|
142
137
|
- lib/money/rates_store/memory.rb
|
143
138
|
- lib/money/version.rb
|
144
139
|
- money.gemspec
|
145
|
-
- spec/bank/base_spec.rb
|
146
|
-
- spec/bank/single_currency_spec.rb
|
147
|
-
- spec/bank/variable_exchange_spec.rb
|
148
|
-
- spec/currency/heuristics_spec.rb
|
149
|
-
- spec/currency/loader_spec.rb
|
150
|
-
- spec/currency_spec.rb
|
151
|
-
- spec/locale_backend/i18n_spec.rb
|
152
|
-
- spec/locale_backend/legacy_spec.rb
|
153
|
-
- spec/money/allocation_spec.rb
|
154
|
-
- spec/money/arithmetic_spec.rb
|
155
|
-
- spec/money/constructors_spec.rb
|
156
|
-
- spec/money/formatting_spec.rb
|
157
|
-
- spec/money/locale_backend_spec.rb
|
158
|
-
- spec/money_spec.rb
|
159
|
-
- spec/rates_store/memory_spec.rb
|
160
|
-
- spec/spec_helper.rb
|
161
|
-
- spec/support/shared_examples/money_examples.rb
|
162
140
|
homepage: https://rubymoney.github.io/money
|
163
141
|
licenses:
|
164
142
|
- MIT
|
@@ -181,26 +159,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
181
159
|
- !ruby/object:Gem::Version
|
182
160
|
version: '0'
|
183
161
|
requirements: []
|
184
|
-
|
185
|
-
rubygems_version: 2.6.8
|
162
|
+
rubygems_version: 3.1.2
|
186
163
|
signing_key:
|
187
164
|
specification_version: 4
|
188
165
|
summary: A Ruby Library for dealing with money and currency conversion.
|
189
|
-
test_files:
|
190
|
-
- spec/bank/base_spec.rb
|
191
|
-
- spec/bank/single_currency_spec.rb
|
192
|
-
- spec/bank/variable_exchange_spec.rb
|
193
|
-
- spec/currency/heuristics_spec.rb
|
194
|
-
- spec/currency/loader_spec.rb
|
195
|
-
- spec/currency_spec.rb
|
196
|
-
- spec/locale_backend/i18n_spec.rb
|
197
|
-
- spec/locale_backend/legacy_spec.rb
|
198
|
-
- spec/money/allocation_spec.rb
|
199
|
-
- spec/money/arithmetic_spec.rb
|
200
|
-
- spec/money/constructors_spec.rb
|
201
|
-
- spec/money/formatting_spec.rb
|
202
|
-
- spec/money/locale_backend_spec.rb
|
203
|
-
- spec/money_spec.rb
|
204
|
-
- spec/rates_store/memory_spec.rb
|
205
|
-
- spec/spec_helper.rb
|
206
|
-
- spec/support/shared_examples/money_examples.rb
|
166
|
+
test_files: []
|
data/.coveralls.yml
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
repo_token: lUJ1iIe2hjtyIFZm413PZ38saqD5UOLXo
|
data/.gitignore
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
# Bundler
|
2
|
-
.bundle
|
3
|
-
Gemfile.lock
|
4
|
-
pkg/*
|
5
|
-
bin/
|
6
|
-
|
7
|
-
# Rubinius
|
8
|
-
*.rbc
|
9
|
-
|
10
|
-
# YARD
|
11
|
-
.yardoc
|
12
|
-
yardoc/
|
13
|
-
doc/
|
14
|
-
|
15
|
-
# Project
|
16
|
-
.rbenv-version
|
17
|
-
.rbx
|
18
|
-
.rvmrc
|
19
|
-
.ruby-version
|
20
|
-
.ruby-gemset
|
21
|
-
|
22
|
-
# Spec artifacts
|
23
|
-
/coverage
|
data/.rspec
DELETED
data/.travis.yml
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
---
|
2
|
-
language: ruby
|
3
|
-
sudo: false
|
4
|
-
rvm:
|
5
|
-
- 1.9.3
|
6
|
-
- 2.0
|
7
|
-
- 2.1.10
|
8
|
-
- 2.2.10
|
9
|
-
- 2.3.7
|
10
|
-
- 2.4.4
|
11
|
-
- 2.5.1
|
12
|
-
- 2.6.0
|
13
|
-
- rbx-3
|
14
|
-
- jruby-9.0.5.0
|
15
|
-
- jruby-9.1.17.0
|
16
|
-
- jruby-9.2.0.0
|
17
|
-
- ruby-head
|
18
|
-
- jruby-head
|
19
|
-
matrix:
|
20
|
-
allow_failures:
|
21
|
-
- rvm: ruby-head
|
22
|
-
- rvm: jruby-head
|
23
|
-
- rvm: rbx-3
|
24
|
-
fast_finish: true
|
25
|
-
before_install:
|
26
|
-
- gem update bundler
|
27
|
-
script: bundle exec rspec spec
|
28
|
-
notifications:
|
29
|
-
email:
|
30
|
-
- semmons99@gmail.com
|
31
|
-
- andreas@aloop.org
|
32
|
-
- weppos@weppos.net
|
data/AUTHORS
DELETED
@@ -1,131 +0,0 @@
|
|
1
|
-
Abhay Kumar
|
2
|
-
Adrian Longley
|
3
|
-
Alexander Ross
|
4
|
-
Alex Speller
|
5
|
-
Andreas Loupasakis
|
6
|
-
Andrei
|
7
|
-
Andrew White
|
8
|
-
Andrius Chamentauskas
|
9
|
-
Anthony Hristov
|
10
|
-
Anthony Sellitti
|
11
|
-
banjerluke
|
12
|
-
Bartosz Dz
|
13
|
-
bbozo
|
14
|
-
Benjamin Grössing
|
15
|
-
Bill DeRusha
|
16
|
-
Bodaniel Jeanes
|
17
|
-
Brian Jones
|
18
|
-
bUg.
|
19
|
-
Cade Truitt
|
20
|
-
Casper Thomsen
|
21
|
-
Chad Boyd
|
22
|
-
Choongmin Lee
|
23
|
-
Chris Kampmeier
|
24
|
-
Christian Billen
|
25
|
-
Clarke Brunsdon
|
26
|
-
Daniel Sherson
|
27
|
-
Dave Kroondyk
|
28
|
-
Doug Droper
|
29
|
-
Douglas Miller
|
30
|
-
Ed Saunders
|
31
|
-
Edwin Vlieg
|
32
|
-
Eloy
|
33
|
-
Evan Alter
|
34
|
-
Exoth
|
35
|
-
Filipe Goncalves
|
36
|
-
Francisco Trindade
|
37
|
-
François Beausoleil
|
38
|
-
François Klingler
|
39
|
-
Fred Liang
|
40
|
-
Gabriel Gilder
|
41
|
-
Gee-Hsien Chuang
|
42
|
-
George Millo
|
43
|
-
Hakan Ensari
|
44
|
-
Hongli Lai
|
45
|
-
Ilia Lobsanov
|
46
|
-
Ivan Shamatov
|
47
|
-
Ingo Wichmann
|
48
|
-
Jacob Atzen
|
49
|
-
James Cotterill
|
50
|
-
James Hunt
|
51
|
-
Jean-Louis Giordano
|
52
|
-
Jean-Philippe Doyle
|
53
|
-
Jell
|
54
|
-
Jérémy Lecour
|
55
|
-
Jeremy McNevin
|
56
|
-
Jesse Cooke
|
57
|
-
Jim Kingdon
|
58
|
-
John Duff
|
59
|
-
John Gakos
|
60
|
-
Jonathon M. Abbott
|
61
|
-
Josh Delsman
|
62
|
-
Josh Hepworth
|
63
|
-
Joshua Clayton
|
64
|
-
Julien Boyer
|
65
|
-
Kaleem Ullah
|
66
|
-
Kenichi Kamiya
|
67
|
-
Kenn Ejima
|
68
|
-
Kenneth Salomon
|
69
|
-
kirillian
|
70
|
-
Laurynas Butkus
|
71
|
-
Marcel Scherf
|
72
|
-
Marco Otte-Witte
|
73
|
-
Mateus Gomes
|
74
|
-
Mateusz Wolsza
|
75
|
-
Matias Korhonen
|
76
|
-
Matthew McEachen
|
77
|
-
Matt Jankowski
|
78
|
-
Max Melentiev
|
79
|
-
Michael Irwin
|
80
|
-
Michael J. Cohen
|
81
|
-
Michael Reinsch
|
82
|
-
Michael Rodrigues
|
83
|
-
Mikael Wikman
|
84
|
-
Mike Herrera
|
85
|
-
Mike Połétyn
|
86
|
-
Musannif Zahir
|
87
|
-
Neil Middleton
|
88
|
-
Nihad Abbasov
|
89
|
-
Olek Janiszewski
|
90
|
-
Orien Madgwick
|
91
|
-
Paul McMahon
|
92
|
-
Paulo Diniz
|
93
|
-
Pavan Sudarshan
|
94
|
-
Pavel Gabriel
|
95
|
-
pconnor
|
96
|
-
Pedro Nascimento
|
97
|
-
Pelle Braendgaard
|
98
|
-
Peter Rhoades
|
99
|
-
Phil Cohen
|
100
|
-
pivotal-cloudplanner
|
101
|
-
Prathan Thananart
|
102
|
-
Robert Starsi
|
103
|
-
Romain Gérard
|
104
|
-
Ryan Bigg
|
105
|
-
sankaranarayanan
|
106
|
-
Scott Pierce
|
107
|
-
Semyon Perepelitsa
|
108
|
-
Shane Emmons
|
109
|
-
Simone Carletti
|
110
|
-
Spencer Rinehart
|
111
|
-
Steve Morris
|
112
|
-
Thomas E Enebo
|
113
|
-
Thomas Weymuth
|
114
|
-
Ticean Bennett
|
115
|
-
Tien Nguyen
|
116
|
-
Tim Hart
|
117
|
-
Tim Krins
|
118
|
-
Tobias Luetke
|
119
|
-
Tobias Schmidt
|
120
|
-
Tom Lianza
|
121
|
-
tommeier
|
122
|
-
Troels Knak-Nielsen
|
123
|
-
Tsyren Ochirov
|
124
|
-
Victor Shcherbakov
|
125
|
-
Wei Zhu
|
126
|
-
Yok
|
127
|
-
Yuri Sidorov
|
128
|
-
Yuusuke Takizawa
|
129
|
-
Zubin Henner
|
130
|
-
Бродяной Александр
|
131
|
-
Nicolay Hvidsten
|