shopify-money 3.0.2 → 3.1.0
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 +4 -4
- data/Gemfile.lock +134 -118
- data/README.md +8 -1
- data/config/crypto.yml +15 -0
- data/lib/money/config.rb +2 -1
- data/lib/money/currency/loader.rb +10 -4
- data/lib/money/currency.rb +5 -0
- data/lib/money/deprecations.rb +1 -1
- data/lib/money/parser/simple.rb +1 -1
- data/lib/money/version.rb +1 -1
- data/money.gemspec +1 -0
- data/spec/config_spec.rb +12 -0
- data/spec/currency/loader_spec.rb +18 -0
- data/spec/currency_spec.rb +64 -0
- data/spec/spec_helper.rb +6 -1
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 020a26aff536b7d54d8c1b06b3018b52eda8c4085e87817f9a40f5245ed59d74
|
4
|
+
data.tar.gz: efe3d99e59baeda27fef40583b2e13fdcfb7608771aee5091a6a1663977fe1f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 356eba9a2f547cc8c65f8f9fc0c5464fecc23670fa4bfdb6ed4ae39bd5080e89ec4be947f4ce6a04da51676e89bfbfdf4adefe590566b97993025b496274e145
|
7
|
+
data.tar.gz: d9cea15b3214c263d8318c13355c9c08fc6d38d86bb265a7f2d68cd91ee29284c41814882230f6e87891cba00e6e7e486a9505ef1373af878363689c9048963b
|
data/Gemfile.lock
CHANGED
@@ -1,34 +1,34 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
shopify-money (3.0
|
4
|
+
shopify-money (3.1.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
actioncable (7.2.
|
10
|
-
actionpack (= 7.2.
|
11
|
-
activesupport (= 7.2.
|
9
|
+
actioncable (7.2.2.1)
|
10
|
+
actionpack (= 7.2.2.1)
|
11
|
+
activesupport (= 7.2.2.1)
|
12
12
|
nio4r (~> 2.0)
|
13
13
|
websocket-driver (>= 0.6.1)
|
14
14
|
zeitwerk (~> 2.6)
|
15
|
-
actionmailbox (7.2.
|
16
|
-
actionpack (= 7.2.
|
17
|
-
activejob (= 7.2.
|
18
|
-
activerecord (= 7.2.
|
19
|
-
activestorage (= 7.2.
|
20
|
-
activesupport (= 7.2.
|
15
|
+
actionmailbox (7.2.2.1)
|
16
|
+
actionpack (= 7.2.2.1)
|
17
|
+
activejob (= 7.2.2.1)
|
18
|
+
activerecord (= 7.2.2.1)
|
19
|
+
activestorage (= 7.2.2.1)
|
20
|
+
activesupport (= 7.2.2.1)
|
21
21
|
mail (>= 2.8.0)
|
22
|
-
actionmailer (7.2.
|
23
|
-
actionpack (= 7.2.
|
24
|
-
actionview (= 7.2.
|
25
|
-
activejob (= 7.2.
|
26
|
-
activesupport (= 7.2.
|
22
|
+
actionmailer (7.2.2.1)
|
23
|
+
actionpack (= 7.2.2.1)
|
24
|
+
actionview (= 7.2.2.1)
|
25
|
+
activejob (= 7.2.2.1)
|
26
|
+
activesupport (= 7.2.2.1)
|
27
27
|
mail (>= 2.8.0)
|
28
28
|
rails-dom-testing (~> 2.2)
|
29
|
-
actionpack (7.2.
|
30
|
-
actionview (= 7.2.
|
31
|
-
activesupport (= 7.2.
|
29
|
+
actionpack (7.2.2.1)
|
30
|
+
actionview (= 7.2.2.1)
|
31
|
+
activesupport (= 7.2.2.1)
|
32
32
|
nokogiri (>= 1.8.5)
|
33
33
|
racc
|
34
34
|
rack (>= 2.2.4, < 3.2)
|
@@ -37,36 +37,37 @@ GEM
|
|
37
37
|
rails-dom-testing (~> 2.2)
|
38
38
|
rails-html-sanitizer (~> 1.6)
|
39
39
|
useragent (~> 0.16)
|
40
|
-
actiontext (7.2.
|
41
|
-
actionpack (= 7.2.
|
42
|
-
activerecord (= 7.2.
|
43
|
-
activestorage (= 7.2.
|
44
|
-
activesupport (= 7.2.
|
40
|
+
actiontext (7.2.2.1)
|
41
|
+
actionpack (= 7.2.2.1)
|
42
|
+
activerecord (= 7.2.2.1)
|
43
|
+
activestorage (= 7.2.2.1)
|
44
|
+
activesupport (= 7.2.2.1)
|
45
45
|
globalid (>= 0.6.0)
|
46
46
|
nokogiri (>= 1.8.5)
|
47
|
-
actionview (7.2.
|
48
|
-
activesupport (= 7.2.
|
47
|
+
actionview (7.2.2.1)
|
48
|
+
activesupport (= 7.2.2.1)
|
49
49
|
builder (~> 3.1)
|
50
50
|
erubi (~> 1.11)
|
51
51
|
rails-dom-testing (~> 2.2)
|
52
52
|
rails-html-sanitizer (~> 1.6)
|
53
|
-
activejob (7.2.
|
54
|
-
activesupport (= 7.2.
|
53
|
+
activejob (7.2.2.1)
|
54
|
+
activesupport (= 7.2.2.1)
|
55
55
|
globalid (>= 0.3.6)
|
56
|
-
activemodel (7.2.
|
57
|
-
activesupport (= 7.2.
|
58
|
-
activerecord (7.2.
|
59
|
-
activemodel (= 7.2.
|
60
|
-
activesupport (= 7.2.
|
56
|
+
activemodel (7.2.2.1)
|
57
|
+
activesupport (= 7.2.2.1)
|
58
|
+
activerecord (7.2.2.1)
|
59
|
+
activemodel (= 7.2.2.1)
|
60
|
+
activesupport (= 7.2.2.1)
|
61
61
|
timeout (>= 0.4.0)
|
62
|
-
activestorage (7.2.
|
63
|
-
actionpack (= 7.2.
|
64
|
-
activejob (= 7.2.
|
65
|
-
activerecord (= 7.2.
|
66
|
-
activesupport (= 7.2.
|
62
|
+
activestorage (7.2.2.1)
|
63
|
+
actionpack (= 7.2.2.1)
|
64
|
+
activejob (= 7.2.2.1)
|
65
|
+
activerecord (= 7.2.2.1)
|
66
|
+
activesupport (= 7.2.2.1)
|
67
67
|
marcel (~> 1.0)
|
68
|
-
activesupport (7.2.
|
68
|
+
activesupport (7.2.2.1)
|
69
69
|
base64
|
70
|
+
benchmark (>= 0.3)
|
70
71
|
bigdecimal
|
71
72
|
concurrent-ruby (~> 1.0, >= 1.3.1)
|
72
73
|
connection_pool (>= 2.2.5)
|
@@ -76,14 +77,15 @@ GEM
|
|
76
77
|
minitest (>= 5.1)
|
77
78
|
securerandom (>= 0.3)
|
78
79
|
tzinfo (~> 2.0, >= 2.0.5)
|
79
|
-
ast (2.4.
|
80
|
+
ast (2.4.3)
|
80
81
|
base64 (0.2.0)
|
81
|
-
|
82
|
+
benchmark (0.4.0)
|
83
|
+
bigdecimal (3.1.9)
|
82
84
|
builder (3.3.0)
|
83
|
-
byebug (
|
85
|
+
byebug (12.0.0)
|
84
86
|
coderay (1.1.3)
|
85
|
-
concurrent-ruby (1.3.
|
86
|
-
connection_pool (2.
|
87
|
+
concurrent-ruby (1.3.5)
|
88
|
+
connection_pool (2.5.0)
|
87
89
|
crass (1.0.6)
|
88
90
|
database_cleaner (2.0.2)
|
89
91
|
database_cleaner-active_record (>= 2, < 3)
|
@@ -91,22 +93,24 @@ GEM
|
|
91
93
|
activerecord (>= 5.a)
|
92
94
|
database_cleaner-core (~> 2.0.0)
|
93
95
|
database_cleaner-core (2.0.1)
|
94
|
-
date (3.
|
96
|
+
date (3.4.1)
|
95
97
|
diff-lcs (1.5.1)
|
96
98
|
docile (1.4.1)
|
97
99
|
drb (2.2.1)
|
98
|
-
erubi (1.13.
|
100
|
+
erubi (1.13.1)
|
99
101
|
globalid (1.2.1)
|
100
102
|
activesupport (>= 6.1)
|
101
|
-
i18n (1.14.
|
103
|
+
i18n (1.14.7)
|
102
104
|
concurrent-ruby (~> 1.0)
|
103
|
-
io-console (0.
|
104
|
-
irb (1.
|
105
|
+
io-console (0.8.0)
|
106
|
+
irb (1.15.2)
|
107
|
+
pp (>= 0.6.0)
|
105
108
|
rdoc (>= 4.0.0)
|
106
109
|
reline (>= 0.4.2)
|
107
|
-
json (2.
|
108
|
-
language_server-protocol (3.17.0.
|
109
|
-
|
110
|
+
json (2.10.2)
|
111
|
+
language_server-protocol (3.17.0.4)
|
112
|
+
lint_roller (1.1.0)
|
113
|
+
logger (1.7.0)
|
110
114
|
loofah (2.24.0)
|
111
115
|
crass (~> 1.0.2)
|
112
116
|
nokogiri (>= 1.12.0)
|
@@ -119,75 +123,81 @@ GEM
|
|
119
123
|
method_source (1.1.0)
|
120
124
|
mini_mime (1.1.5)
|
121
125
|
mini_portile2 (2.8.8)
|
122
|
-
minitest (5.25.
|
123
|
-
net-imap (0.5.
|
126
|
+
minitest (5.25.5)
|
127
|
+
net-imap (0.5.6)
|
124
128
|
date
|
125
129
|
net-protocol
|
126
130
|
net-pop (0.1.2)
|
127
131
|
net-protocol
|
128
132
|
net-protocol (0.2.2)
|
129
133
|
timeout
|
130
|
-
net-smtp (0.5.
|
134
|
+
net-smtp (0.5.1)
|
131
135
|
net-protocol
|
132
|
-
nio4r (2.7.
|
133
|
-
nokogiri (1.18.
|
136
|
+
nio4r (2.7.4)
|
137
|
+
nokogiri (1.18.7)
|
134
138
|
mini_portile2 (~> 2.8.2)
|
135
139
|
racc (~> 1.4)
|
136
|
-
nokogiri (1.18.
|
140
|
+
nokogiri (1.18.7-aarch64-linux-gnu)
|
137
141
|
racc (~> 1.4)
|
138
|
-
nokogiri (1.18.
|
142
|
+
nokogiri (1.18.7-arm-linux-gnu)
|
139
143
|
racc (~> 1.4)
|
140
|
-
nokogiri (1.18.
|
144
|
+
nokogiri (1.18.7-arm64-darwin)
|
141
145
|
racc (~> 1.4)
|
142
|
-
nokogiri (1.18.
|
146
|
+
nokogiri (1.18.7-x86_64-darwin)
|
143
147
|
racc (~> 1.4)
|
144
|
-
nokogiri (1.18.
|
148
|
+
nokogiri (1.18.7-x86_64-linux-gnu)
|
145
149
|
racc (~> 1.4)
|
150
|
+
ostruct (0.6.1)
|
146
151
|
parallel (1.26.3)
|
147
|
-
parser (3.3.
|
152
|
+
parser (3.3.7.4)
|
148
153
|
ast (~> 2.4.1)
|
149
154
|
racc
|
150
|
-
|
155
|
+
pp (0.6.2)
|
156
|
+
prettyprint
|
157
|
+
prettyprint (0.2.0)
|
158
|
+
prism (1.4.0)
|
159
|
+
pry (0.15.2)
|
151
160
|
coderay (~> 1.1)
|
152
161
|
method_source (~> 1.0)
|
153
|
-
pry-byebug (3.
|
154
|
-
byebug (~>
|
155
|
-
pry (>= 0.13, < 0.
|
156
|
-
psych (5.
|
162
|
+
pry-byebug (3.11.0)
|
163
|
+
byebug (~> 12.0)
|
164
|
+
pry (>= 0.13, < 0.16)
|
165
|
+
psych (5.2.3)
|
166
|
+
date
|
157
167
|
stringio
|
158
168
|
racc (1.8.1)
|
159
|
-
rack (3.1.
|
160
|
-
rack-session (2.
|
169
|
+
rack (3.1.12)
|
170
|
+
rack-session (2.1.0)
|
171
|
+
base64 (>= 0.1.0)
|
161
172
|
rack (>= 3.0.0)
|
162
|
-
rack-test (2.
|
173
|
+
rack-test (2.2.0)
|
163
174
|
rack (>= 1.3)
|
164
|
-
rackup (2.1
|
175
|
+
rackup (2.2.1)
|
165
176
|
rack (>= 3)
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
activesupport (= 7.2.1.1)
|
177
|
+
rails (7.2.2.1)
|
178
|
+
actioncable (= 7.2.2.1)
|
179
|
+
actionmailbox (= 7.2.2.1)
|
180
|
+
actionmailer (= 7.2.2.1)
|
181
|
+
actionpack (= 7.2.2.1)
|
182
|
+
actiontext (= 7.2.2.1)
|
183
|
+
actionview (= 7.2.2.1)
|
184
|
+
activejob (= 7.2.2.1)
|
185
|
+
activemodel (= 7.2.2.1)
|
186
|
+
activerecord (= 7.2.2.1)
|
187
|
+
activestorage (= 7.2.2.1)
|
188
|
+
activesupport (= 7.2.2.1)
|
179
189
|
bundler (>= 1.15.0)
|
180
|
-
railties (= 7.2.
|
190
|
+
railties (= 7.2.2.1)
|
181
191
|
rails-dom-testing (2.2.0)
|
182
192
|
activesupport (>= 5.0.0)
|
183
193
|
minitest
|
184
194
|
nokogiri (>= 1.6)
|
185
|
-
rails-html-sanitizer (1.6.
|
195
|
+
rails-html-sanitizer (1.6.2)
|
186
196
|
loofah (~> 2.21)
|
187
197
|
nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
|
188
|
-
railties (7.2.
|
189
|
-
actionpack (= 7.2.
|
190
|
-
activesupport (= 7.2.
|
198
|
+
railties (7.2.2.1)
|
199
|
+
actionpack (= 7.2.2.1)
|
200
|
+
activesupport (= 7.2.2.1)
|
191
201
|
irb (~> 1.13)
|
192
202
|
rackup (>= 1.0.0)
|
193
203
|
rake (>= 12.2)
|
@@ -195,10 +205,10 @@ GEM
|
|
195
205
|
zeitwerk (~> 2.6)
|
196
206
|
rainbow (3.1.1)
|
197
207
|
rake (13.2.1)
|
198
|
-
rdoc (6.
|
208
|
+
rdoc (6.13.1)
|
199
209
|
psych (>= 4.0.0)
|
200
|
-
regexp_parser (2.
|
201
|
-
reline (0.
|
210
|
+
regexp_parser (2.10.0)
|
211
|
+
reline (0.6.1)
|
202
212
|
io-console (~> 0.5)
|
203
213
|
rspec (3.13.0)
|
204
214
|
rspec-core (~> 3.13.0)
|
@@ -213,49 +223,54 @@ GEM
|
|
213
223
|
diff-lcs (>= 1.2.0, < 2.0)
|
214
224
|
rspec-support (~> 3.13.0)
|
215
225
|
rspec-support (3.13.1)
|
216
|
-
rubocop (1.
|
226
|
+
rubocop (1.75.2)
|
217
227
|
json (~> 2.3)
|
218
|
-
language_server-protocol (
|
228
|
+
language_server-protocol (~> 3.17.0.2)
|
229
|
+
lint_roller (~> 1.1.0)
|
219
230
|
parallel (~> 1.10)
|
220
231
|
parser (>= 3.3.0.2)
|
221
232
|
rainbow (>= 2.2.2, < 4.0)
|
222
|
-
regexp_parser (>= 2.
|
223
|
-
rubocop-ast (>= 1.
|
233
|
+
regexp_parser (>= 2.9.3, < 3.0)
|
234
|
+
rubocop-ast (>= 1.44.0, < 2.0)
|
224
235
|
ruby-progressbar (~> 1.7)
|
225
|
-
unicode-display_width (>= 2.4.0, <
|
226
|
-
rubocop-ast (1.
|
227
|
-
parser (>= 3.3.
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
rubocop (
|
236
|
+
unicode-display_width (>= 2.4.0, < 4.0)
|
237
|
+
rubocop-ast (1.44.0)
|
238
|
+
parser (>= 3.3.7.2)
|
239
|
+
prism (~> 1.4)
|
240
|
+
rubocop-performance (1.25.0)
|
241
|
+
lint_roller (~> 1.1)
|
242
|
+
rubocop (>= 1.75.0, < 2.0)
|
243
|
+
rubocop-ast (>= 1.38.0, < 2.0)
|
244
|
+
rubocop-shopify (2.16.0)
|
245
|
+
rubocop (~> 1.62)
|
233
246
|
ruby-progressbar (1.13.0)
|
234
|
-
securerandom (0.
|
247
|
+
securerandom (0.4.1)
|
235
248
|
simplecov (0.22.0)
|
236
249
|
docile (~> 1.1)
|
237
250
|
simplecov-html (~> 0.11)
|
238
251
|
simplecov_json_formatter (~> 0.1)
|
239
252
|
simplecov-html (0.13.1)
|
240
253
|
simplecov_json_formatter (0.1.4)
|
241
|
-
sqlite3 (2.
|
242
|
-
sqlite3 (2.
|
243
|
-
sqlite3 (2.
|
244
|
-
sqlite3 (2.
|
245
|
-
sqlite3 (2.
|
246
|
-
sqlite3 (2.
|
247
|
-
stringio (3.1.
|
254
|
+
sqlite3 (2.6.0-aarch64-linux-gnu)
|
255
|
+
sqlite3 (2.6.0-arm-linux-gnu)
|
256
|
+
sqlite3 (2.6.0-arm64-darwin)
|
257
|
+
sqlite3 (2.6.0-x86-linux-gnu)
|
258
|
+
sqlite3 (2.6.0-x86_64-darwin)
|
259
|
+
sqlite3 (2.6.0-x86_64-linux-gnu)
|
260
|
+
stringio (3.1.6)
|
248
261
|
thor (1.3.2)
|
249
|
-
timeout (0.4.
|
262
|
+
timeout (0.4.3)
|
250
263
|
tzinfo (2.0.6)
|
251
264
|
concurrent-ruby (~> 1.0)
|
252
|
-
unicode-display_width (
|
253
|
-
|
254
|
-
|
255
|
-
|
265
|
+
unicode-display_width (3.1.4)
|
266
|
+
unicode-emoji (~> 4.0, >= 4.0.4)
|
267
|
+
unicode-emoji (4.0.4)
|
268
|
+
useragent (0.16.11)
|
269
|
+
websocket-driver (0.7.7)
|
270
|
+
base64
|
256
271
|
websocket-extensions (>= 0.1.0)
|
257
272
|
websocket-extensions (0.1.5)
|
258
|
-
zeitwerk (2.
|
273
|
+
zeitwerk (2.6.18)
|
259
274
|
|
260
275
|
PLATFORMS
|
261
276
|
aarch64-linux
|
@@ -268,6 +283,7 @@ PLATFORMS
|
|
268
283
|
DEPENDENCIES
|
269
284
|
bundler
|
270
285
|
database_cleaner (~> 2.0)
|
286
|
+
ostruct
|
271
287
|
pry-byebug
|
272
288
|
rails (~> 7.2)
|
273
289
|
rspec (~> 3.2)
|
data/README.md
CHANGED
@@ -157,6 +157,14 @@ Money.new(money.value * exchange_rate, "JPY")
|
|
157
157
|
money.convert_currency(exchange_rate, "JPY")
|
158
158
|
```
|
159
159
|
|
160
|
+
### Crypto Currencies
|
161
|
+
To enable support for currencies listed in `crypto.yml` use
|
162
|
+
``` ruby
|
163
|
+
Money.configure do |config|
|
164
|
+
config.experimental_crypto_currencies = true
|
165
|
+
end
|
166
|
+
```
|
167
|
+
|
160
168
|
## Money column
|
161
169
|
|
162
170
|
Since money internally uses BigDecimal it's logical to use a `decimal` column
|
@@ -237,4 +245,3 @@ To release a new version of the gem, follow these steps:
|
|
237
245
|
|
238
246
|
Copyright (c) 2011 Shopify. See LICENSE.txt for
|
239
247
|
further details.
|
240
|
-
|
data/config/crypto.yml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
usdc:
|
2
|
+
priority: 100
|
3
|
+
iso_code: "USDC"
|
4
|
+
name: "USD Coin"
|
5
|
+
symbol: "USDC"
|
6
|
+
disambiguate_symbol: USDC
|
7
|
+
alternate_symbols: []
|
8
|
+
subunit: Cent
|
9
|
+
subunit_to_unit: 100
|
10
|
+
symbol_first: false
|
11
|
+
html_entity: "$"
|
12
|
+
decimal_mark: "."
|
13
|
+
thousands_separator: ","
|
14
|
+
iso_numeric: ''
|
15
|
+
smallest_denomination: 1
|
data/lib/money/config.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
class Money
|
4
4
|
class Config
|
5
|
-
attr_accessor :default_currency, :legacy_json_format, :legacy_deprecations
|
5
|
+
attr_accessor :default_currency, :legacy_json_format, :legacy_deprecations, :experimental_crypto_currencies
|
6
6
|
|
7
7
|
def legacy_default_currency!
|
8
8
|
@default_currency ||= Money::NULL_CURRENCY
|
@@ -20,6 +20,7 @@ class Money
|
|
20
20
|
@default_currency = nil
|
21
21
|
@legacy_json_format = false
|
22
22
|
@legacy_deprecations = false
|
23
|
+
@experimental_crypto_currencies = false
|
23
24
|
end
|
24
25
|
|
25
26
|
def without_legacy_deprecations(&block)
|
@@ -5,14 +5,20 @@ require 'yaml'
|
|
5
5
|
class Money
|
6
6
|
class Currency
|
7
7
|
module Loader
|
8
|
+
CURRENCY_DATA_PATH = File.expand_path("../../../config", __dir__)
|
9
|
+
|
8
10
|
class << self
|
9
11
|
def load_currencies
|
10
|
-
|
12
|
+
currencies = {}
|
13
|
+
currencies.merge!(YAML.load_file("#{CURRENCY_DATA_PATH}/currency_historic.yml"))
|
14
|
+
currencies.merge!(YAML.load_file("#{CURRENCY_DATA_PATH}/currency_non_iso.yml"))
|
15
|
+
currencies.merge!(YAML.load_file("#{CURRENCY_DATA_PATH}/currency_iso.yml"))
|
16
|
+
deep_deduplicate!(currencies)
|
17
|
+
end
|
11
18
|
|
19
|
+
def load_crypto_currencies
|
12
20
|
currencies = {}
|
13
|
-
currencies.merge!(YAML.load_file("#{
|
14
|
-
currencies.merge!(YAML.load_file("#{currency_data_path}/currency_non_iso.yml"))
|
15
|
-
currencies.merge!(YAML.load_file("#{currency_data_path}/currency_iso.yml"))
|
21
|
+
currencies.merge!(YAML.load_file("#{CURRENCY_DATA_PATH}/crypto.yml"))
|
16
22
|
deep_deduplicate!(currencies)
|
17
23
|
end
|
18
24
|
|
data/lib/money/currency.rb
CHANGED
@@ -26,6 +26,10 @@ class Money
|
|
26
26
|
def currencies
|
27
27
|
@@currencies ||= Loader.load_currencies
|
28
28
|
end
|
29
|
+
|
30
|
+
def crypto_currencies
|
31
|
+
@@crypto_currencies ||= Loader.load_crypto_currencies
|
32
|
+
end
|
29
33
|
end
|
30
34
|
|
31
35
|
attr_reader :iso_code,
|
@@ -41,6 +45,7 @@ class Money
|
|
41
45
|
|
42
46
|
def initialize(currency_iso)
|
43
47
|
data = self.class.currencies[currency_iso]
|
48
|
+
data = self.class.crypto_currencies[currency_iso] if data.nil? && Money.config.experimental_crypto_currencies
|
44
49
|
raise UnknownCurrency, "Invalid iso4217 currency '#{currency_iso}'" unless data
|
45
50
|
@symbol = data['symbol']
|
46
51
|
@disambiguate_symbol = data['disambiguate_symbol'] || data['symbol']
|
data/lib/money/deprecations.rb
CHANGED
data/lib/money/parser/simple.rb
CHANGED
data/lib/money/version.rb
CHANGED
data/money.gemspec
CHANGED
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
|
|
18
18
|
|
19
19
|
s.add_development_dependency("bundler")
|
20
20
|
s.add_development_dependency("database_cleaner", "~> 2.0")
|
21
|
+
s.add_development_dependency("ostruct")
|
21
22
|
s.add_development_dependency("rails", "~> 7.2")
|
22
23
|
s.add_development_dependency("rspec", "~> 3.2")
|
23
24
|
s.add_development_dependency("simplecov", ">= 0")
|
data/spec/config_spec.rb
CHANGED
@@ -63,4 +63,16 @@ RSpec.describe "Money::Config" do
|
|
63
63
|
end
|
64
64
|
end
|
65
65
|
end
|
66
|
+
|
67
|
+
describe 'experimental_crypto_currencies' do
|
68
|
+
it 'defaults to false' do
|
69
|
+
expect(Money::Config.new.experimental_crypto_currencies).to eq(false)
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'can be set to true' do
|
73
|
+
config = Money::Config.new
|
74
|
+
config.experimental_crypto_currencies = true
|
75
|
+
expect(config.experimental_crypto_currencies).to eq(true)
|
76
|
+
end
|
77
|
+
end
|
66
78
|
end
|
@@ -19,4 +19,22 @@ RSpec.describe Money::Currency::Loader do
|
|
19
19
|
expect(subject.load_currencies['eek']['iso_code']).to eq('EEK')
|
20
20
|
end
|
21
21
|
end
|
22
|
+
|
23
|
+
describe 'load_crypto_currencies' do
|
24
|
+
it 'loads the crypto currency file' do
|
25
|
+
expect(subject.load_crypto_currencies['usdc']['iso_code']).to eq('USDC')
|
26
|
+
expect(subject.load_crypto_currencies['usdc']['name']).to eq('USD Coin')
|
27
|
+
expect(subject.load_crypto_currencies['usdc']['symbol']).to eq('USDC')
|
28
|
+
expect(subject.load_crypto_currencies['usdc']['disambiguate_symbol']).to eq('USDC')
|
29
|
+
expect(subject.load_crypto_currencies['usdc']['subunit_to_unit']).to eq(100)
|
30
|
+
expect(subject.load_crypto_currencies['usdc']['smallest_denomination']).to eq(1)
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'returns frozen and deduplicated data' do
|
34
|
+
currencies = subject.load_crypto_currencies
|
35
|
+
expect(currencies).to be_frozen
|
36
|
+
expect(currencies['usdc']).to be_frozen
|
37
|
+
expect(currencies['usdc']['iso_code']).to be_frozen
|
38
|
+
end
|
39
|
+
end
|
22
40
|
end
|
data/spec/currency_spec.rb
CHANGED
@@ -17,6 +17,20 @@ RSpec.describe "Currency" do
|
|
17
17
|
|
18
18
|
let(:currency) { Money::Currency.new('usd') }
|
19
19
|
|
20
|
+
let(:mock_crypto_currency) do
|
21
|
+
{
|
22
|
+
"usdc" => {
|
23
|
+
"iso_code" => "USDC",
|
24
|
+
"name" => "USD Coin",
|
25
|
+
"symbol" => "USDC",
|
26
|
+
"disambiguate_symbol" => "USDC",
|
27
|
+
"subunit_to_unit" => 100,
|
28
|
+
"smallest_denomination" => 1,
|
29
|
+
"decimal_mark" => "."
|
30
|
+
}
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
20
34
|
describe ".new" do
|
21
35
|
it "is constructable with a uppercase string" do
|
22
36
|
expect(Money::Currency.new('USD').iso_code).to eq('USD')
|
@@ -37,6 +51,24 @@ RSpec.describe "Currency" do
|
|
37
51
|
it "raises when the currency is nil" do
|
38
52
|
expect { Money::Currency.new(nil) }.to raise_error(Money::Currency::UnknownCurrency)
|
39
53
|
end
|
54
|
+
|
55
|
+
it "looks up crypto currencies when enabled" do
|
56
|
+
|
57
|
+
allow(Money::Currency).to receive(:currencies).and_return({})
|
58
|
+
allow(Money::Currency).to receive(:crypto_currencies).and_return(mock_crypto_currency)
|
59
|
+
|
60
|
+
configure(experimental_crypto_currencies: true) do
|
61
|
+
currency = Money::Currency.new('USDC')
|
62
|
+
expect(currency.iso_code).to eq('USDC')
|
63
|
+
expect(currency.symbol).to eq('USDC')
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
it "doesn't look up crypto currencies when disabled" do
|
68
|
+
configure(experimental_crypto_currencies: false) do
|
69
|
+
expect(Money::Currency.find("USDC")).to be_nil
|
70
|
+
end
|
71
|
+
end
|
40
72
|
end
|
41
73
|
|
42
74
|
describe ".find" do
|
@@ -47,6 +79,23 @@ RSpec.describe "Currency" do
|
|
47
79
|
it "returns a valid currency" do
|
48
80
|
expect(Money::Currency.find('usd')).to eq(Money::Currency.new('usd'))
|
49
81
|
end
|
82
|
+
|
83
|
+
it "returns a crypto currency when enabled" do
|
84
|
+
allow(Money::Currency).to receive(:currencies).and_return({})
|
85
|
+
allow(Money::Currency).to receive(:crypto_currencies).and_return(mock_crypto_currency)
|
86
|
+
|
87
|
+
configure(experimental_crypto_currencies: true) do
|
88
|
+
expect(Money::Currency.find('USDC')).not_to eq(nil)
|
89
|
+
expect(Money::Currency.find('USDC').symbol).to eq("USDC")
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
it "returns nil for crypto currency when disabled" do
|
94
|
+
configure(experimental_crypto_currencies: false) do
|
95
|
+
expect(Money.config.experimental_crypto_currencies).to eq(false)
|
96
|
+
expect(Money::Currency.find('USDC')).to eq(nil)
|
97
|
+
end
|
98
|
+
end
|
50
99
|
end
|
51
100
|
|
52
101
|
describe ".find!" do
|
@@ -59,6 +108,21 @@ RSpec.describe "Currency" do
|
|
59
108
|
end
|
60
109
|
end
|
61
110
|
|
111
|
+
describe ".crypto_currencies" do
|
112
|
+
it "loads crypto currencies from the loader" do
|
113
|
+
old_currencies = Money::Currency.class_variable_get(:@@crypto_currencies) rescue nil
|
114
|
+
Money::Currency.class_variable_set(:@@crypto_currencies, nil)
|
115
|
+
|
116
|
+
allow(Money::Currency::Loader).to receive(:load_crypto_currencies).and_return(mock_crypto_currency)
|
117
|
+
|
118
|
+
expect(Money::Currency.crypto_currencies).to eq(mock_crypto_currency)
|
119
|
+
expect(Money::Currency.crypto_currencies).to eq(mock_crypto_currency) # Second call to verify caching
|
120
|
+
expect(Money::Currency::Loader).to have_received(:load_crypto_currencies).once
|
121
|
+
|
122
|
+
Money::Currency.class_variable_set(:@@crypto_currencies, old_currencies) if old_currencies
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
62
126
|
CURRENCY_DATA.each do |attribute, value|
|
63
127
|
describe "##{attribute}" do
|
64
128
|
it 'returns the correct value' do
|
data/spec/spec_helper.rb
CHANGED
@@ -12,6 +12,7 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
12
12
|
require 'rspec'
|
13
13
|
require 'pry-byebug'
|
14
14
|
require 'database_cleaner'
|
15
|
+
require 'ostruct'
|
15
16
|
|
16
17
|
require 'rails'
|
17
18
|
require 'active_record'
|
@@ -71,16 +72,20 @@ RSpec::Matchers.define :quack_like do
|
|
71
72
|
end
|
72
73
|
|
73
74
|
|
74
|
-
def configure(default_currency: nil, legacy_json_format: nil, legacy_deprecations: nil, legacy_default_currency: nil)
|
75
|
+
def configure(default_currency: nil, legacy_json_format: nil, legacy_deprecations: nil, legacy_default_currency: nil, experimental_crypto_currencies: nil)
|
76
|
+
old_currencies = Money::Currency.class_variable_get(:@@loaded_currencies) rescue {}
|
77
|
+
Money::Currency.class_variable_set(:@@loaded_currencies, {})
|
75
78
|
old_config = Money.config
|
76
79
|
Money.config = Money::Config.new.tap do |config|
|
77
80
|
config.default_currency = default_currency if default_currency
|
78
81
|
config.legacy_json_format! if legacy_json_format
|
79
82
|
config.legacy_deprecations! if legacy_deprecations
|
80
83
|
config.legacy_default_currency! if legacy_default_currency
|
84
|
+
config.experimental_crypto_currencies = experimental_crypto_currencies unless experimental_crypto_currencies.nil?
|
81
85
|
end
|
82
86
|
yield
|
83
87
|
ensure
|
88
|
+
Money::Currency.class_variable_set(:@@loaded_currencies, old_currencies)
|
84
89
|
Money.config = old_config
|
85
90
|
end
|
86
91
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shopify-money
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shopify Inc
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: bundler
|
@@ -37,6 +37,20 @@ dependencies:
|
|
37
37
|
- - "~>"
|
38
38
|
- !ruby/object:Gem::Version
|
39
39
|
version: '2.0'
|
40
|
+
- !ruby/object:Gem::Dependency
|
41
|
+
name: ostruct
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
type: :development
|
48
|
+
prerelease: false
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
40
54
|
- !ruby/object:Gem::Dependency
|
41
55
|
name: rails
|
42
56
|
requirement: !ruby/object:Gem::Requirement
|
@@ -115,6 +129,7 @@ files:
|
|
115
129
|
- Rakefile
|
116
130
|
- UPGRADING.md
|
117
131
|
- bin/console
|
132
|
+
- config/crypto.yml
|
118
133
|
- config/currency_historic.yml
|
119
134
|
- config/currency_iso.yml
|
120
135
|
- config/currency_non_iso.yml
|
@@ -188,7 +203,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
188
203
|
- !ruby/object:Gem::Version
|
189
204
|
version: '0'
|
190
205
|
requirements: []
|
191
|
-
rubygems_version: 3.6.
|
206
|
+
rubygems_version: 3.6.8
|
192
207
|
specification_version: 4
|
193
208
|
summary: Shopify's money gem
|
194
209
|
test_files: []
|