From 4b0b007c3748320f8ec2c6261ebc3f143d251b15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julia=20Lo=CC=81pez?= Date: Thu, 11 Dec 2025 11:28:37 +0100 Subject: [PATCH 1/6] align gemspec with others in the organization --- Gemfile | 11 ++++++++-- money-collection.gemspec | 43 +++++++++++++++++++++------------------- 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/Gemfile b/Gemfile index 146c753..4c8cda1 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,11 @@ -source 'https://rubygems.org' +# frozen_string_literal: true + +source "https://rubygems.org" + +# Specs +gem "minitest" + +# Tasks +gem "rake" -# Specify your gem's dependencies in money-collection.gemspec gemspec diff --git a/money-collection.gemspec b/money-collection.gemspec index 4e10c43..ce2dd1e 100644 --- a/money-collection.gemspec +++ b/money-collection.gemspec @@ -1,26 +1,29 @@ -# coding: utf-8 -lib = File.expand_path('../lib', __FILE__) +# frozen_string_literal: true + +lib = File.expand_path("lib", __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) -require 'money/collection/version' +require "money/collection/version" -Gem::Specification.new do |spec| - spec.name = "money-collection" - spec.version = Money::Collection::VERSION - spec.authors = ["lulalala"] - spec.email = ["mark@goodlife.tw"] - spec.summary = %q{Optimized operation on collection of Money objects} - spec.description = spec.summary - spec.homepage = "https://github.com/lulalala/money-collection" - spec.license = "MIT" +Gem::Specification.new do |s| + s.name = "money-collection" + s.version = Money::Collection::VERSION + s.platform = Gem::Platform::RUBY + s.authors = ["lulalala"] + s.email = ["mark@goodlife.tw"] + s.homepage = "https://github.com/RubyMoney/money-collection" + s.summary = "Optimized operation on collection of Money objects" + s.description = "Optimized operation on collection of Money objects" + s.license = "MIT" - spec.files = `git ls-files -z`.split("\x0") - spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } - spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) - spec.require_paths = ["lib"] + s.add_dependency "money", "~> 6.3" - spec.add_dependency "money", "~> 6.3" + s.files = `git ls-files -z -- lib/* CHANGELOG.md LICENSE money-collection.gemspec README.md`.split("\x0") + s.require_paths = ["lib"] - spec.add_development_dependency "bundler" - spec.add_development_dependency "rake" - spec.add_development_dependency "minitest" + if s.respond_to?(:metadata) + s.metadata["changelog_uri"] = "https://github.com/RubyMoney/money-collection/blob/main/CHANGELOG.md" + s.metadata["source_code_uri"] = "https://github.com/RubyMoney/money-collection/" + s.metadata["bug_tracker_uri"] = "https://github.com/RubyMoney/money-collection/issues" + s.metadata["rubygems_mfa_required"] = "true" + end end From eacf4605882fcb8a4c606a96494aaa60f0bc8822 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julia=20Lo=CC=81pez?= Date: Thu, 11 Dec 2025 11:31:35 +0100 Subject: [PATCH 2/6] bump to money ~> 7.0 --- money-collection.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/money-collection.gemspec b/money-collection.gemspec index ce2dd1e..f30b221 100644 --- a/money-collection.gemspec +++ b/money-collection.gemspec @@ -15,7 +15,7 @@ Gem::Specification.new do |s| s.description = "Optimized operation on collection of Money objects" s.license = "MIT" - s.add_dependency "money", "~> 6.3" + s.add_dependency "money", "~> 7.0" s.files = `git ls-files -z -- lib/* CHANGELOG.md LICENSE money-collection.gemspec README.md`.split("\x0") s.require_paths = ["lib"] From 0c1a21caec6c75bf312a12a0441486911505f8ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julia=20Lo=CC=81pez?= Date: Thu, 11 Dec 2025 11:34:08 +0100 Subject: [PATCH 3/6] require ruby version >= 3.1 and tweak actions to test with those and jruby --- .github/workflows/ruby.yml | 28 ++++++++++++++-------------- money-collection.gemspec | 2 ++ 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index d7f604a..3f83684 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -1,31 +1,31 @@ -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. -# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake -# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby - name: Ruby on: push: - branches: [ main ] + branches: [main] pull_request: - branches: [ main ] + branches: [main] + +permissions: + contents: read jobs: test: - runs-on: ubuntu-latest strategy: matrix: - ruby-version: ['2.6', '2.7', '3.0'] + ruby-version: ['3.1', '3.2', '3.3', '3.4', 'jruby-9.4', 'jruby-10.0'] steps: - - uses: actions/checkout@v2 + - name: Set up Java for JRuby 10.0 + if: matrix.ruby-version == 'jruby-10.0' + uses: actions/setup-java@v5 + with: + distribution: 'temurin' + java-version: '21' + - name: Checkout repository + uses: actions/checkout@v6 - name: Set up Ruby - # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby, - # change this to (see https://github.com/ruby/setup-ruby#versioning): uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby-version }} diff --git a/money-collection.gemspec b/money-collection.gemspec index f30b221..120759a 100644 --- a/money-collection.gemspec +++ b/money-collection.gemspec @@ -17,6 +17,8 @@ Gem::Specification.new do |s| s.add_dependency "money", "~> 7.0" + s.required_ruby_version = ">= 3.1" + s.files = `git ls-files -z -- lib/* CHANGELOG.md LICENSE money-collection.gemspec README.md`.split("\x0") s.require_paths = ["lib"] From 01042d595cd8a43fcc7c705d22976aaf3c14d96a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julia=20Lo=CC=81pez?= Date: Thu, 11 Dec 2025 11:35:45 +0100 Subject: [PATCH 4/6] bump to 1.0.0 --- CHANGELOG.md | 7 +++++++ lib/money/collection/version.rb | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..0d05e6a --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,7 @@ +# Changelog + +## Unreleased + +## 1.0.0 +- **Breaking change**: Update Money gem dependency to ~> 7.0. See the [Money 7.0 upgrading guide](https://github.com/RubyMoney/money/blob/main/UPGRADING-7.0.md) +- **Breaking change**: Drop support for Ruby < 3.1 diff --git a/lib/money/collection/version.rb b/lib/money/collection/version.rb index b2a2b5f..c428e08 100644 --- a/lib/money/collection/version.rb +++ b/lib/money/collection/version.rb @@ -1,5 +1,5 @@ class Money class Collection - VERSION = "0.1.0" + VERSION = "1.0.0" end end From e5688d59965aa92426ad70828e36edd67981ea64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julia=20Lo=CC=81pez?= Date: Thu, 11 Dec 2025 11:44:37 +0100 Subject: [PATCH 5/6] test improvements to remove deprecations --- spec/helper.rb | 21 --------------- spec/money/collection_spec.rb | 48 +++++++++++++++++------------------ spec/spec_helper.rb | 7 +++++ 3 files changed, 30 insertions(+), 46 deletions(-) delete mode 100644 spec/helper.rb create mode 100644 spec/spec_helper.rb diff --git a/spec/helper.rb b/spec/helper.rb deleted file mode 100644 index 3500be9..0000000 --- a/spec/helper.rb +++ /dev/null @@ -1,21 +0,0 @@ -require 'rubygems' - -begin - require 'bundler' -rescue LoadError => e - STDERR.puts e.message - STDERR.puts "Run `gem install bundler` to install Bundler." - exit e.status_code -end - -begin - Bundler.setup(:default, :development, :test) -rescue Bundler::BundlerError => e - STDERR.puts e.message - STDERR.puts "Run `bundle install` to install missing gems." - exit e.status_code -end - -require 'minitest/spec' -require 'minitest/autorun' - diff --git a/spec/money/collection_spec.rb b/spec/money/collection_spec.rb index b3013c8..1a9b36b 100644 --- a/spec/money/collection_spec.rb +++ b/spec/money/collection_spec.rb @@ -1,6 +1,4 @@ -require 'helper' -require 'money' -require 'money/collection' +require "spec_helper" describe Money::Collection do before do @@ -25,20 +23,20 @@ end it 'has version' do - Money::Collection.const_get('VERSION').wont_be_empty + _(Money::Collection.const_get('VERSION')).wont_be_empty end describe '#sum' do it 'sums with no element' do c = Money::Collection.new - c.sum.must_equal Money.new(0) + _(c.sum).must_equal Money.new(0) end it 'sums with single element' do c = Money::Collection.new c << Money.new(10,:usd) - c.sum.must_equal Money.new(10,:usd) + _(c.sum).must_equal Money.new(10,:usd) end it 'sums same currency' do @@ -50,7 +48,7 @@ c = Money::Collection.new(ary) - c.sum.must_equal Money.new(60,:usd) + _(c.sum).must_equal Money.new(60,:usd) end it 'sums different currencies' do @@ -61,7 +59,7 @@ c = Money::Collection.new(ary) - c.sum.must_equal normal_sum(ary) + _(c.sum).must_equal normal_sum(ary) end it 'sums correctly, avoiding rounding down error' do @@ -73,7 +71,7 @@ c = Money::Collection.new(ary) - c.sum.must_equal Money.new(11,:usd) + _(c.sum).must_equal Money.new(11,:usd) end it 'sums correctly, avoiding rounding twice if possible' do @@ -84,7 +82,7 @@ c = Money::Collection.new(ary) - c.sum(:foo).must_equal Money.new(21,:foo) + _(c.sum(:foo)).must_equal Money.new(21,:foo) end it 'returns sum in the specified currency' do @@ -95,8 +93,8 @@ c = Money::Collection.new(ary) - c.sum('foo').must_equal Money.new(22,:foo) - c.sum('usd').must_equal Money.new(11,:usd) + _(c.sum('foo')).must_equal Money.new(22,:foo) + _(c.sum('usd')).must_equal Money.new(11,:usd) end it 'returns sum in the specified currency and without unnecessary intermediate conversion' do @@ -107,7 +105,7 @@ c = Money::Collection.new(ary) - c.sum('foo').must_equal Money.new(21,:foo) + _(c.sum('foo')).must_equal Money.new(21,:foo) end it 'returns sum large number of Money' do @@ -124,7 +122,7 @@ ) c = Money::Collection.new(ary) - c.sum('foo').must_equal normal_sum(ary) + _(c.sum('foo')).must_equal normal_sum(ary) end end end @@ -138,7 +136,7 @@ ] c = Money::Collection.new(ary) - c.min.must_equal Money.new(1,:usd) + _(c.min).must_equal Money.new(1,:usd) end it 'returns smallest Money objects (from many items)' do ary = 1000.times.map do @@ -147,7 +145,7 @@ c = Money::Collection.new(ary) min = Money.new(1, :usd) c << min - c.min.must_equal min + _(c.min).must_equal min end end @@ -160,7 +158,7 @@ ] c = Money::Collection.new(ary) - c.max.must_equal Money.new(30,:foo) + _(c.max).must_equal Money.new(30,:foo) end it 'returns biggest Money objects (from many items)' do ary = 1000.times.map do @@ -169,7 +167,7 @@ c = Money::Collection.new(ary) max = Money.new(100001, :usd) c << max - c.max.must_equal max + _(c.max).must_equal max end end @@ -183,8 +181,8 @@ c = Money::Collection.new c.concat ary - c.size.must_equal 2 - c.sum('foo').must_equal Money.new(22,:foo) + _(c.size).must_equal 2 + _(c.sum('foo')).must_equal Money.new(22,:foo) end it 'concats Money objects to collection multiple times' do ary = [ @@ -196,8 +194,8 @@ c.concat ary c.concat ary - c.size.must_equal 4 - c.sum('foo').must_equal Money.new(44,:foo) + _(c.size).must_equal 4 + _(c.sum('foo')).must_equal Money.new(44,:foo) end end @@ -208,7 +206,7 @@ c << Money.new(10,:foo) c << Money.new(10,:usd) - c.sum.must_equal Money.new(25,:usd) + _(c.sum).must_equal Money.new(25,:usd) end end @@ -220,8 +218,8 @@ c = Money::Collection.new(ary) c << Money.new(1,:usd) - ary.size.must_equal 1 - ary[0].must_equal m1 + _(ary.size).must_equal 1 + _(ary[0]).must_equal m1 end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..40f6942 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +require "minitest/autorun" +require "money" +require "money/collection" + +Money.default_currency = Money::Currency.new("USD") From eaf1f62fc49405157fd3ef6f0e1531bf60f5902f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julia=20Lo=CC=81pez?= Date: Thu, 11 Dec 2025 11:46:40 +0100 Subject: [PATCH 6/6] claude tweaks in the changelog --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d05e6a..1431210 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,5 +3,13 @@ ## Unreleased ## 1.0.0 + - **Breaking change**: Update Money gem dependency to ~> 7.0. See the [Money 7.0 upgrading guide](https://github.com/RubyMoney/money/blob/main/UPGRADING-7.0.md) - **Breaking change**: Drop support for Ruby < 3.1 + +## 0.1.0 + +- Initial release +- Add `Money::Collection` class for optimized sum/min/max operations on Money objects +- Minimize currency conversions for accuracy and efficiency +- Support enumerable operations with `#concat` and `#<<` methods