money 6.9.0 → 6.16.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +131 -3
  3. data/LICENSE +17 -17
  4. data/README.md +181 -71
  5. data/config/currency_backwards_compatible.json +65 -0
  6. data/config/currency_iso.json +119 -56
  7. data/config/currency_non_iso.json +35 -2
  8. data/lib/money/bank/variable_exchange.rb +22 -12
  9. data/lib/money/currency/loader.rb +15 -13
  10. data/lib/money/currency.rb +38 -39
  11. data/lib/money/locale_backend/base.rb +7 -0
  12. data/lib/money/locale_backend/currency.rb +11 -0
  13. data/lib/money/locale_backend/errors.rb +6 -0
  14. data/lib/money/locale_backend/i18n.rb +25 -0
  15. data/lib/money/locale_backend/legacy.rb +28 -0
  16. data/lib/money/money/allocation.rb +46 -0
  17. data/lib/money/money/arithmetic.rb +33 -15
  18. data/lib/money/money/constructors.rb +1 -2
  19. data/lib/money/money/formatter.rb +399 -0
  20. data/lib/money/money/formatting_rules.rb +142 -0
  21. data/lib/money/money/locale_backend.rb +22 -0
  22. data/lib/money/money.rb +235 -187
  23. data/lib/money/rates_store/memory.rb +24 -24
  24. data/lib/money/version.rb +1 -1
  25. data/money.gemspec +14 -8
  26. metadata +36 -56
  27. data/.coveralls.yml +0 -1
  28. data/.gitignore +0 -23
  29. data/.rspec +0 -1
  30. data/.travis.yml +0 -26
  31. data/AUTHORS +0 -126
  32. data/CONTRIBUTING.md +0 -17
  33. data/Gemfile +0 -16
  34. data/Rakefile +0 -17
  35. data/lib/money/money/formatting.rb +0 -426
  36. data/spec/bank/base_spec.rb +0 -79
  37. data/spec/bank/single_currency_spec.rb +0 -13
  38. data/spec/bank/variable_exchange_spec.rb +0 -265
  39. data/spec/currency/heuristics_spec.rb +0 -11
  40. data/spec/currency/loader_spec.rb +0 -19
  41. data/spec/currency_spec.rb +0 -359
  42. data/spec/money/arithmetic_spec.rb +0 -693
  43. data/spec/money/constructors_spec.rb +0 -103
  44. data/spec/money/formatting_spec.rb +0 -757
  45. data/spec/money_spec.rb +0 -778
  46. data/spec/rates_store/memory_spec.rb +0 -69
  47. data/spec/spec_helper.rb +0 -28
@@ -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] rt Optional initial exchange rate data.
21
- def initialize(opts = {}, rt = {})
22
- @options, @index = opts, rt
23
- @mutex = Mutex.new
24
- @in_transaction = false
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
- transaction { index[rate_key_for(currency_iso_from, currency_iso_to)] = rate }
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,25 +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
- transaction { index[rate_key_for(currency_iso_from, currency_iso_to)] }
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
- [self.class, index, options]
67
+ guard.synchronize do
68
+ return [self.class, options, rates.dup]
69
+ end
62
70
  end
63
71
 
64
-
65
72
  # Wraps block execution in a thread-safe transaction
66
73
  def transaction(&block)
67
- if @in_transaction || options[:without_mutex]
68
- block.call self
69
- else
70
- @mutex.synchronize do
71
- @in_transaction = true
72
- result = block.call
73
- @in_transaction = false
74
- result
75
- end
74
+ guard.synchronize do
75
+ yield
76
76
  end
77
77
  end
78
78
 
@@ -89,19 +89,19 @@ class Money
89
89
  # puts [iso_from, iso_to, rate].join
90
90
  # end
91
91
  def each_rate(&block)
92
- enum = Enumerator.new do |yielder|
93
- index.each do |key, rate|
92
+ return to_enum(:each_rate) unless block_given?
93
+
94
+ guard.synchronize do
95
+ rates.each do |key, rate|
94
96
  iso_from, iso_to = key.split(INDEX_KEY_SEPARATOR)
95
- yielder.yield iso_from, iso_to, rate
97
+ yield iso_from, iso_to, rate
96
98
  end
97
99
  end
98
-
99
- block_given? ? enum.each(&block) : enum
100
100
  end
101
101
 
102
102
  private
103
103
 
104
- attr_reader :index, :options
104
+ attr_reader :rates, :options, :guard
105
105
 
106
106
  # Return the rate hashkey for the given currencies.
107
107
  #
data/lib/money/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Money
2
- VERSION = "6.9.0"
2
+ VERSION = '6.16.0'
3
3
  end
data/money.gemspec CHANGED
@@ -7,23 +7,29 @@ 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 = ["Shane Emmons"]
11
- s.email = ["shane@emmons.io"]
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."
15
15
  s.license = "MIT"
16
16
 
17
- s.add_dependency 'i18n', ['>= 0.6.4', '< 0.9']
17
+ s.add_dependency 'i18n', [">= 0.6.4", '<= 2']
18
18
 
19
- s.add_development_dependency "bundler", "~> 1.3"
19
+ s.add_development_dependency "bundler"
20
20
  s.add_development_dependency "rake"
21
- s.add_development_dependency "rspec", "~> 3.4.0"
22
- s.add_development_dependency "yard", "~> 0.8"
23
- s.add_development_dependency "kramdown", "~> 1.1"
21
+ s.add_development_dependency "rspec", "~> 3.4"
22
+ s.add_development_dependency "yard", "~> 0.9.11"
23
+ s.add_development_dependency "kramdown", "~> 2.3"
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"]
29
+
30
+ if s.respond_to?(:metadata)
31
+ s.metadata['changelog_uri'] = 'https://github.com/RubyMoney/money/blob/master/CHANGELOG.md'
32
+ s.metadata['source_code_uri'] = 'https://github.com/RubyMoney/money/'
33
+ s.metadata['bug_tracker_uri'] = 'https://github.com/RubyMoney/money/issues'
34
+ end
29
35
  end
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.9.0
4
+ version: 6.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shane Emmons
8
- autorequire:
8
+ - Anthony Dmitriyev
9
+ autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2017-04-20 00:00:00.000000000 Z
12
+ date: 2021-05-09 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: i18n
@@ -17,9 +18,9 @@ dependencies:
17
18
  - - ">="
18
19
  - !ruby/object:Gem::Version
19
20
  version: 0.6.4
20
- - - "<"
21
+ - - "<="
21
22
  - !ruby/object:Gem::Version
22
- version: '0.9'
23
+ version: '2'
23
24
  type: :runtime
24
25
  prerelease: false
25
26
  version_requirements: !ruby/object:Gem::Requirement
@@ -27,23 +28,23 @@ dependencies:
27
28
  - - ">="
28
29
  - !ruby/object:Gem::Version
29
30
  version: 0.6.4
30
- - - "<"
31
+ - - "<="
31
32
  - !ruby/object:Gem::Version
32
- version: '0.9'
33
+ version: '2'
33
34
  - !ruby/object:Gem::Dependency
34
35
  name: bundler
35
36
  requirement: !ruby/object:Gem::Requirement
36
37
  requirements:
37
- - - "~>"
38
+ - - ">="
38
39
  - !ruby/object:Gem::Version
39
- version: '1.3'
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: '1.3'
47
+ version: '0'
47
48
  - !ruby/object:Gem::Dependency
48
49
  name: rake
49
50
  requirement: !ruby/object:Gem::Requirement
@@ -64,60 +65,53 @@ dependencies:
64
65
  requirements:
65
66
  - - "~>"
66
67
  - !ruby/object:Gem::Version
67
- version: 3.4.0
68
+ version: '3.4'
68
69
  type: :development
69
70
  prerelease: false
70
71
  version_requirements: !ruby/object:Gem::Requirement
71
72
  requirements:
72
73
  - - "~>"
73
74
  - !ruby/object:Gem::Version
74
- version: 3.4.0
75
+ version: '3.4'
75
76
  - !ruby/object:Gem::Dependency
76
77
  name: yard
77
78
  requirement: !ruby/object:Gem::Requirement
78
79
  requirements:
79
80
  - - "~>"
80
81
  - !ruby/object:Gem::Version
81
- version: '0.8'
82
+ version: 0.9.11
82
83
  type: :development
83
84
  prerelease: false
84
85
  version_requirements: !ruby/object:Gem::Requirement
85
86
  requirements:
86
87
  - - "~>"
87
88
  - !ruby/object:Gem::Version
88
- version: '0.8'
89
+ version: 0.9.11
89
90
  - !ruby/object:Gem::Dependency
90
91
  name: kramdown
91
92
  requirement: !ruby/object:Gem::Requirement
92
93
  requirements:
93
94
  - - "~>"
94
95
  - !ruby/object:Gem::Version
95
- version: '1.1'
96
+ version: '2.3'
96
97
  type: :development
97
98
  prerelease: false
98
99
  version_requirements: !ruby/object:Gem::Requirement
99
100
  requirements:
100
101
  - - "~>"
101
102
  - !ruby/object:Gem::Version
102
- version: '1.1'
103
+ version: '2.3'
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
@@ -128,30 +122,29 @@ files:
128
122
  - lib/money/currency.rb
129
123
  - lib/money/currency/heuristics.rb
130
124
  - lib/money/currency/loader.rb
125
+ - lib/money/locale_backend/base.rb
126
+ - lib/money/locale_backend/currency.rb
127
+ - lib/money/locale_backend/errors.rb
128
+ - lib/money/locale_backend/i18n.rb
129
+ - lib/money/locale_backend/legacy.rb
131
130
  - lib/money/money.rb
131
+ - lib/money/money/allocation.rb
132
132
  - lib/money/money/arithmetic.rb
133
133
  - lib/money/money/constructors.rb
134
- - lib/money/money/formatting.rb
134
+ - lib/money/money/formatter.rb
135
+ - lib/money/money/formatting_rules.rb
136
+ - lib/money/money/locale_backend.rb
135
137
  - lib/money/rates_store/memory.rb
136
138
  - lib/money/version.rb
137
139
  - money.gemspec
138
- - spec/bank/base_spec.rb
139
- - spec/bank/single_currency_spec.rb
140
- - spec/bank/variable_exchange_spec.rb
141
- - spec/currency/heuristics_spec.rb
142
- - spec/currency/loader_spec.rb
143
- - spec/currency_spec.rb
144
- - spec/money/arithmetic_spec.rb
145
- - spec/money/constructors_spec.rb
146
- - spec/money/formatting_spec.rb
147
- - spec/money_spec.rb
148
- - spec/rates_store/memory_spec.rb
149
- - spec/spec_helper.rb
150
140
  homepage: https://rubymoney.github.io/money
151
141
  licenses:
152
142
  - MIT
153
- metadata: {}
154
- post_install_message:
143
+ metadata:
144
+ changelog_uri: https://github.com/RubyMoney/money/blob/master/CHANGELOG.md
145
+ source_code_uri: https://github.com/RubyMoney/money/
146
+ bug_tracker_uri: https://github.com/RubyMoney/money/issues
147
+ post_install_message:
155
148
  rdoc_options: []
156
149
  require_paths:
157
150
  - lib
@@ -166,21 +159,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
166
159
  - !ruby/object:Gem::Version
167
160
  version: '0'
168
161
  requirements: []
169
- rubyforge_project:
170
- rubygems_version: 2.6.8
171
- signing_key:
162
+ rubygems_version: 3.2.3
163
+ signing_key:
172
164
  specification_version: 4
173
165
  summary: A Ruby Library for dealing with money and currency conversion.
174
- test_files:
175
- - spec/bank/base_spec.rb
176
- - spec/bank/single_currency_spec.rb
177
- - spec/bank/variable_exchange_spec.rb
178
- - spec/currency/heuristics_spec.rb
179
- - spec/currency/loader_spec.rb
180
- - spec/currency_spec.rb
181
- - spec/money/arithmetic_spec.rb
182
- - spec/money/constructors_spec.rb
183
- - spec/money/formatting_spec.rb
184
- - spec/money_spec.rb
185
- - spec/rates_store/memory_spec.rb
186
- - spec/spec_helper.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
@@ -1 +0,0 @@
1
- --require spec_helper
data/.travis.yml DELETED
@@ -1,26 +0,0 @@
1
- language: ruby
2
- sudo: false
3
- rvm:
4
- - 1.9.3
5
- - 2.0.0
6
- - 2.1.10
7
- - 2.2.5
8
- - 2.3.1
9
- - 2.4.0
10
- - rbx-2
11
- - jruby-9.0.5.0
12
- - jruby-9.1.2.0
13
- - ruby-head
14
- - jruby-head
15
- matrix:
16
- allow_failures:
17
- - rvm: ruby-head
18
- - rvm: jruby-head
19
- - rvm: rbx-2
20
- fast_finish: true
21
- script: bundle exec rspec spec
22
- notifications:
23
- email:
24
- - semmons99@gmail.com
25
- - andreas@aloop.org
26
- - weppos@weppos.net
data/AUTHORS DELETED
@@ -1,126 +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
- Gabriel Gilder
40
- Gee-Hsien Chuang
41
- George Millo
42
- Hakan Ensari
43
- Hongli Lai
44
- Ilia Lobsanov
45
- Ingo Wichmann
46
- Jacob Atzen
47
- James Cotterill
48
- James Hunt
49
- Jean-Louis Giordano
50
- Jean-Philippe Doyle
51
- Jell
52
- Jérémy Lecour
53
- Jeremy McNevin
54
- Jesse Cooke
55
- Jim Kingdon
56
- John Duff
57
- John Gakos
58
- Jonathon M. Abbott
59
- Josh Delsman
60
- Josh Hepworth
61
- Joshua Clayton
62
- Julien Boyer
63
- Kaleem Ullah
64
- Kenichi Kamiya
65
- Kenn Ejima
66
- kirillian
67
- Laurynas Butkus
68
- Marcel Scherf
69
- Marco Otte-Witte
70
- Mateus Gomes
71
- Mateusz Wolsza
72
- Matias Korhonen
73
- Matthew McEachen
74
- Matt Jankowski
75
- Max Melentiev
76
- Michael Irwin
77
- Michael J. Cohen
78
- Michael Reinsch
79
- Michael Rodrigues
80
- Mikael Wikman
81
- Mike Herrera
82
- Mike Połétyn
83
- Musannif Zahir
84
- Neil Middleton
85
- Nihad Abbasov
86
- Olek Janiszewski
87
- Orien Madgwick
88
- Paul McMahon
89
- Paulo Diniz
90
- Pavan Sudarshan
91
- Pavel Gabriel
92
- pconnor
93
- Pedro Nascimento
94
- Pelle Braendgaard
95
- Peter Rhoades
96
- Phil Cohen
97
- pivotal-cloudplanner
98
- Prathan Thananart
99
- Robert Starsi
100
- Romain Gérard
101
- Ryan Bigg
102
- sankaranarayanan
103
- Scott Pierce
104
- Semyon Perepelitsa
105
- Shane Emmons
106
- Simone Carletti
107
- Spencer Rinehart
108
- Steve Morris
109
- Thomas E Enebo
110
- Thomas Weymuth
111
- Ticean Bennett
112
- Tien Nguyen
113
- Tim Hart
114
- Tobias Luetke
115
- Tobias Schmidt
116
- Tom Lianza
117
- tommeier
118
- Troels Knak-Nielsen
119
- Tsyren Ochirov
120
- Victor Shcherbakov
121
- Wei Zhu
122
- Yok
123
- Yuri Sidorov
124
- Yuusuke Takizawa
125
- Zubin Henner
126
- Бродяной Александр
data/CONTRIBUTING.md DELETED
@@ -1,17 +0,0 @@
1
- # Contribution Guidelines
2
-
3
- ## Steps
4
-
5
- 1. Fork [the repo](https://github.com/RubyMoney/money)
6
- 2. Grab dependencies: `bundle install`
7
- 3. Make sure everything is working: `bundle exec rake spec`
8
- 4. Make your changes
9
- 5. Test your changes
10
- 5. Create a Pull Request
11
- 6. Celebrate!!!!!
12
-
13
- ## Notes
14
-
15
- When contributing, please make sure to update the CHANGELOG and AUTHORS files
16
- when you submit your pull request. Upon merging of your first pull request,
17
- you will be given commit access to the repository.
data/Gemfile DELETED
@@ -1,16 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'coveralls', '>= 0.8.17', :require => false
4
- gem 'pry', :require => false
5
-
6
- # JSON gem no longer supports ruby < 2.0.0
7
- if defined?(JRUBY_VERSION)
8
- gem 'json'
9
- elsif RUBY_VERSION =~ /^1/
10
- # Legacy gem locks for ruby 1.9.x
11
- gem 'json', '~> 1.8.3'
12
- gem 'tins', '~> 1.6.0'
13
- gem 'term-ansicolor', '< 1.4'
14
- end
15
-
16
- gemspec
data/Rakefile DELETED
@@ -1,17 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rake/clean"
3
- require "rspec/core/rake_task"
4
-
5
- CLOBBER.include('doc', '.yardoc')
6
-
7
- require "yard"
8
-
9
- YARD::Rake::YardocTask.new do |t|
10
- t.options << "--files" << "CHANGELOG.md,LICENSE"
11
- end
12
-
13
- RSpec::Core::RakeTask.new(:spec) do |t|
14
- t.fail_on_error = false
15
- end
16
-
17
- task default: :spec