shopify-money 1.3.0 → 2.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 968f61cd2788112e0310dad876e0100eef9bdc375b39d10b7a34e98cb23650fc
4
- data.tar.gz: 279e00665cf1561add517a797afc0d732410813233da3dfe6c09225de9108445
3
+ metadata.gz: 591c60e355144246085ac254fe82b099c85ab4bf7f1e37672b8082331bd9d0aa
4
+ data.tar.gz: 493384ced59c9a37ebc798b4cb499bd0532ea30243c8248704bf0df6f776ca0f
5
5
  SHA512:
6
- metadata.gz: 5abf64ebc32b62bbb31906b977a05e66362dc68453c454efedfe0c83ae5743454c526882fbec437f4874d36ae5d384947c64175a8d50fba0fb339c58d77500c5
7
- data.tar.gz: 76a439a0dca761dc12b3fd44e90737aee88fe26f11ed20af1ab9eba45ce20d6fa55265c9130ee034548d5b799621eef4d328808ca12fcfdcca6b02e258a496b4
6
+ metadata.gz: 1867df0795206ccd5996b1d8471f23f60340ace3e5e685ddbb98f601402a7748aade38263dbc7f12971c1e4368919cb0122c53eacf0b96b96df44189be3ca32e
7
+ data.tar.gz: 9ed8869fce8e66c4e9aee275ac3a28c24db47fd2ae8537f2ff3ee100541f122cd9b8b87e7ca102567b976548eb04b53b06f6c560f2e6e12dc3ca506e0bb87f01
@@ -1,7 +1,7 @@
1
1
  name: tests
2
2
 
3
3
  on: [push, pull_request]
4
-
4
+
5
5
  jobs:
6
6
  build:
7
7
 
@@ -9,7 +9,7 @@ jobs:
9
9
 
10
10
  strategy:
11
11
  matrix:
12
- ruby: ['2.6', '2.7', '3.0', '3.1', '3.2']
12
+ ruby: ['3.0', '3.1', '3.2', '3.3']
13
13
 
14
14
  name: Ruby ${{ matrix.ruby }}
15
15
  steps:
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 #=> Currency.new("USD")
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") == Money.new(5, "USD") # 5 USD
48
- Money.from_subunits(5, "JPY") == Money.new(5, "JPY") # 5 JPY
49
- Money.from_subunits(5000, "TND") == Money.new(5, "TND") # 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
@@ -3,7 +3,7 @@
3
3
  ---
4
4
  name: money
5
5
  up:
6
- - ruby: 3.2.0
6
+ - ruby: 3.3.0
7
7
  - bundler
8
8
  commands:
9
9
  test: bundle exec rspec
data/lib/money/helpers.rb CHANGED
@@ -16,8 +16,6 @@ class Money
16
16
  def value_to_decimal(num)
17
17
  value =
18
18
  case num
19
- when Money
20
- num.value
21
19
  when BigDecimal
22
20
  num
23
21
  when nil, 0, ''
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
- if Money.config.legacy_deprecations
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
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  class Money
3
- VERSION = "1.3.0"
3
+ VERSION = "2.0.0"
4
4
  end
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 = '>= 2.6'
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) }
@@ -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("1.2.3")
7
- expect(Money.active_support_deprecator.deprecation_horizon).to eq("2.0.0")
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 'returns the value of a money object' do
11
- expect(subject.value_to_decimal(money)).to eq(amount)
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: 1.3.0
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: 2023-08-09 00:00:00.000000000 Z
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: '2.6'
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.4.17
189
+ rubygems_version: 3.5.5
190
190
  signing_key:
191
191
  specification_version: 4
192
192
  summary: Shopify's money gem