shopify-money 1.3.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/tests.yml +2 -2
- data/README.md +22 -5
- data/dev.yml +1 -1
- data/lib/money/helpers.rb +0 -2
- data/lib/money/money.rb +2 -7
- data/lib/money/version.rb +1 -1
- data/money.gemspec +1 -1
- data/spec/deprecations_spec.rb +2 -2
- data/spec/helpers_spec.rb +2 -2
- data/spec/money_spec.rb +0 -7
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 591c60e355144246085ac254fe82b099c85ab4bf7f1e37672b8082331bd9d0aa
|
4
|
+
data.tar.gz: 493384ced59c9a37ebc798b4cb499bd0532ea30243c8248704bf0df6f776ca0f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1867df0795206ccd5996b1d8471f23f60340ace3e5e685ddbb98f601402a7748aade38263dbc7f12971c1e4368919cb0122c53eacf0b96b96df44189be3ca32e
|
7
|
+
data.tar.gz: 9ed8869fce8e66c4e9aee275ac3a28c24db47fd2ae8537f2ff3ee100541f122cd9b8b87e7ca102567b976548eb04b53b06f6c560f2e6e12dc3ca506e0bb87f01
|
data/.github/workflows/tests.yml
CHANGED
data/README.md
CHANGED
@@ -29,7 +29,7 @@ require 'money'
|
|
29
29
|
# 10.00 USD
|
30
30
|
money = Money.new(10.00, "USD")
|
31
31
|
money.subunits #=> 1000
|
32
|
-
money.currency
|
32
|
+
money.currency #=> Money::Currency.new("USD")
|
33
33
|
|
34
34
|
# Comparisons
|
35
35
|
Money.new(1000, "USD") == Money.new(1000, "USD") #=> true
|
@@ -40,13 +40,30 @@ Money.new(1000, "USD") != Money.new(1000, "EUR") #=> true
|
|
40
40
|
# Arithmetic
|
41
41
|
Money.new(1000, "USD") + Money.new(500, "USD") == Money.new(1500, "USD")
|
42
42
|
Money.new(1000, "USD") - Money.new(200, "USD") == Money.new(800, "USD")
|
43
|
-
Money.new(1000, "USD") / 5 == Money.new(200, "USD")
|
44
43
|
Money.new(1000, "USD") * 5 == Money.new(5000, "USD")
|
45
44
|
|
45
|
+
m = Money.new(1000, "USD")
|
46
|
+
# Splitting money evenly
|
47
|
+
m.split(2) == [Money.new(500, "USD"), Money.new(500, "USD")]
|
48
|
+
m.split(3).map(&:value) == [333.34, 333.33, 333.33]
|
49
|
+
m.calculate_splits(2) == { Money.new(500, "USD") => 2 }
|
50
|
+
m.calculate_splits(3) == { Money.new(333.34, "USD") => 1, Money.new(333.33, "USD") =>2 }
|
51
|
+
|
52
|
+
# Allocating money proportionally
|
53
|
+
m.allocate([0.50, 0.25, 0.25]).map(&:value) == [500, 250, 250]
|
54
|
+
m.allocate([Rational(2, 3), Rational(1, 3)]).map(&:value) == [666.67, 333.33]
|
55
|
+
|
56
|
+
## Allocating up to a cutoff
|
57
|
+
m.allocate_max_amounts([500, 300, 200]).map(&:value) == [500, 300, 200]
|
58
|
+
m.allocate_max_amounts([500, 300, 300]).map(&:value) == [454.55, 272.73, 272.72]
|
59
|
+
|
60
|
+
# Clamp
|
61
|
+
Money.new(50, "USD").clamp(1, 100) == Money.new(50, "USD")
|
62
|
+
|
46
63
|
# Unit to subunit conversions
|
47
|
-
Money.from_subunits(500, "USD")
|
48
|
-
Money.from_subunits(5, "JPY")
|
49
|
-
Money.from_subunits(5000, "TND") == Money.new(5, "TND")
|
64
|
+
Money.from_subunits(500, "USD") == Money.new(5, "USD") # 5 USD
|
65
|
+
Money.from_subunits(5, "JPY") == Money.new(5, "JPY") # 5 JPY
|
66
|
+
Money.from_subunits(5000, "TND") == Money.new(5, "TND") # 5 TND
|
50
67
|
```
|
51
68
|
|
52
69
|
## Currency
|
data/dev.yml
CHANGED
data/lib/money/helpers.rb
CHANGED
data/lib/money/money.rb
CHANGED
@@ -137,13 +137,8 @@ class Money
|
|
137
137
|
end
|
138
138
|
|
139
139
|
def *(numeric)
|
140
|
-
unless numeric.is_a?(Numeric)
|
141
|
-
|
142
|
-
Money.deprecate("Multiplying Money with #{numeric.class.name} is deprecated and will be removed in the next major release.")
|
143
|
-
else
|
144
|
-
raise ArgumentError, "Money objects can only be multiplied by a Numeric"
|
145
|
-
end
|
146
|
-
end
|
140
|
+
raise ArgumentError, "Money objects can only be multiplied by a Numeric" unless numeric.is_a?(Numeric)
|
141
|
+
|
147
142
|
return self if numeric == 1
|
148
143
|
Money.new(value.to_r * numeric, currency)
|
149
144
|
end
|
data/lib/money/version.rb
CHANGED
data/money.gemspec
CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
|
|
22
22
|
s.add_development_dependency("database_cleaner", "~> 1.6")
|
23
23
|
s.add_development_dependency("sqlite3", "~> 1.4.2")
|
24
24
|
|
25
|
-
s.required_ruby_version = '>=
|
25
|
+
s.required_ruby_version = '>= 3.0'
|
26
26
|
|
27
27
|
s.files = `git ls-files`.split($/)
|
28
28
|
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
data/spec/deprecations_spec.rb
CHANGED
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
|
4
4
|
RSpec.describe "deprecations" do
|
5
5
|
it "has the deprecation_horizon as the next major release" do
|
6
|
-
allow(Money).to receive(:const_get).with('VERSION').and_return("
|
7
|
-
expect(Money.active_support_deprecator.deprecation_horizon).to eq("
|
6
|
+
allow(Money).to receive(:const_get).with('VERSION').and_return("2.0.0")
|
7
|
+
expect(Money.active_support_deprecator.deprecation_horizon).to eq("3.0.0")
|
8
8
|
end
|
9
9
|
end
|
data/spec/helpers_spec.rb
CHANGED
@@ -7,8 +7,8 @@ RSpec.describe Money::Helpers do
|
|
7
7
|
let (:amount) { BigDecimal('1.23') }
|
8
8
|
let (:money) { Money.new(amount) }
|
9
9
|
|
10
|
-
it '
|
11
|
-
expect
|
10
|
+
it 'raises when provided with a money object' do
|
11
|
+
expect { subject.value_to_decimal(money) }.to raise_error(ArgumentError)
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'returns itself if it is already a big decimal' do
|
data/spec/money_spec.rb
CHANGED
@@ -290,13 +290,6 @@ RSpec.describe "Money" do
|
|
290
290
|
expect(((1.0 / 12) * Money.new(3.3))).to eq(Money.new(0.28))
|
291
291
|
end
|
292
292
|
|
293
|
-
it "legacy_deprecations is multipliable by a money object" do
|
294
|
-
configure(legacy_deprecations: true) do
|
295
|
-
expect(Money).to receive(:deprecate).once
|
296
|
-
expect((Money.new(3.3, 'USD') * Money.new(1, 'USD'))).to eq(Money.new(3.3, 'USD'))
|
297
|
-
end
|
298
|
-
end
|
299
|
-
|
300
293
|
it "raises when multiplied by a money object" do
|
301
294
|
expect{ (Money.new(3.3) * Money.new(1)) }.to raise_error(ArgumentError)
|
302
295
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shopify-money
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shopify Inc
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -179,14 +179,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
179
179
|
requirements:
|
180
180
|
- - ">="
|
181
181
|
- !ruby/object:Gem::Version
|
182
|
-
version: '
|
182
|
+
version: '3.0'
|
183
183
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
184
184
|
requirements:
|
185
185
|
- - ">="
|
186
186
|
- !ruby/object:Gem::Version
|
187
187
|
version: '0'
|
188
188
|
requirements: []
|
189
|
-
rubygems_version: 3.
|
189
|
+
rubygems_version: 3.5.5
|
190
190
|
signing_key:
|
191
191
|
specification_version: 4
|
192
192
|
summary: Shopify's money gem
|