splittable 0.0.9 → 0.0.11

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: 11114efe2ce13eb5f799082f87b27b9031d61c88dc4bbf15429bbb96c5038a62
4
- data.tar.gz: 214bcc97eb502853d46db7e0b2678570269b6226658cf3c11df921607372fc75
3
+ metadata.gz: e877a1af5de7bdb1be9b80f87ebd3dd2621503a883d68836841390bd44f8e36d
4
+ data.tar.gz: 95801f4cb44fd1559f57342161150d577bcfc45f707fc045ebf61c0d8b0ffe84
5
5
  SHA512:
6
- metadata.gz: 3b47c45ce0f0078632eef4fd3ca2914c17398d75c1e5691d344db08bc9b81a165abe6165763861819e090ffdf264ac0aaf6d5cee9415649d28fbd7f67e7e02e7
7
- data.tar.gz: 7d4722cc082db9dcb8d450f7fdd876f71842ee61ea8f3ec7716a695cef935ec15b08c09c6473c2f95894f467e14902045069ff5549b5ccd1d8a19352e628cee5
6
+ metadata.gz: 871675d8c1cc4761dac01a2871d96696d15549cdc83eceaca8eb2abfe3001bd0c4d17d73088b883aff3047621cbed619b4807c1de45263bbe2a437dce3c1a5eb
7
+ data.tar.gz: 92e64f05b626ce2aca9d8c2318b3ad893838f24cef1b0dbe56c52ef4d75ed7d7832f50d41dde2843e4b9d9908afe6d8edd786db149386160010506bc4b1b1791
@@ -0,0 +1,11 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: 'bundler'
4
+ directory: '/'
5
+ schedule:
6
+ interval: 'weekly'
7
+
8
+ - package-ecosystem: 'github-actions'
9
+ directory: '/'
10
+ schedule:
11
+ interval: 'weekly'
@@ -4,21 +4,49 @@ on:
4
4
  push:
5
5
  branches:
6
6
  - master
7
- tags:
8
- - v*
9
7
 
10
8
  jobs:
11
9
  publish:
12
10
  if: github.event_name == 'push' && github.ref == 'refs/heads/master'
13
11
  runs-on: ubuntu-latest
14
12
 
13
+ permissions:
14
+ id-token: write
15
+ contents: write
16
+
15
17
  steps:
16
- - uses: actions/checkout@v3
18
+ - uses: actions/checkout@v7
19
+
20
+ - name: Decide whether this version is unpublished
21
+ id: release
22
+ run: |
23
+ version=$(ruby -r ./lib/splittable/version.rb -e 'puts Splittable::VERSION')
24
+ echo "version=${version}" >> "$GITHUB_OUTPUT"
25
+ if git ls-remote --exit-code --tags origin "refs/tags/v${version}"; then
26
+ echo "Version v${version} is already tagged. Skipping publish."
27
+ echo "publish=false" >> "$GITHUB_OUTPUT"
28
+ else
29
+ echo "Version v${version} has no tag yet."
30
+ echo "publish=true" >> "$GITHUB_OUTPUT"
31
+ fi
32
+
33
+ - name: Set up Ruby
34
+ if: steps.release.outputs.publish == 'true'
35
+ uses: ruby/setup-ruby@v1
36
+ with:
37
+ ruby-version: .ruby-version
38
+ bundler-cache: true
17
39
 
18
40
  - name: Release Gem
19
- uses: m4rcelotoledo/publish-rubygems-action@master
41
+ if: steps.release.outputs.publish == 'true'
42
+ uses: rubygems/release-gem@v1
43
+
44
+ - name: Tag release version
45
+ if: steps.release.outputs.publish == 'true'
20
46
  env:
21
- RUBYGEMS_API_KEY: ${{secrets.RUBYGEMS_RELEASE}}
22
- GIT_EMAIL: automated_release@gmail.com
23
- GIT_NAME: 'Automated Release'
24
- RELEASE_COMMAND: bundle exec rake release
47
+ VERSION: ${{ steps.release.outputs.version }}
48
+ run: |
49
+ git config user.name 'Automated Release'
50
+ git config user.email 'automated_release@gmail.com'
51
+ git tag -a "v${VERSION}" -m "Release v${VERSION}"
52
+ git push origin "refs/tags/v${VERSION}"
@@ -10,27 +10,18 @@ on:
10
10
  jobs:
11
11
  build:
12
12
  runs-on: ubuntu-latest
13
- strategy:
14
- matrix:
15
- ruby: [ '3.4.6' ]
16
13
 
17
14
  steps:
18
- - uses: actions/checkout@v3
15
+ - uses: actions/checkout@v7
19
16
 
20
- - name: Set up Ruby version specified in `.ruby-version`
17
+ - name: Set up Ruby
18
+ uses: ruby/setup-ruby@v1
21
19
  with:
22
20
  ruby-version: .ruby-version
23
- uses: ruby/setup-ruby@v1
24
-
25
- - name: Install dependencies
26
- run: bundle install --jobs 4 --retry 3
21
+ bundler-cache: true
27
22
 
28
23
  - name: Run tests with RSpec
29
- env:
30
- RAILS_ENV: test
31
24
  run: bundle exec rspec
32
25
 
33
26
  - name: Run Rubocop
34
- env:
35
- RAILS_ENV: test
36
27
  run: bundle exec rubocop --config .rubocop.yml
data/.rubocop.yml CHANGED
@@ -5,7 +5,7 @@ plugins:
5
5
 
6
6
  AllCops:
7
7
  NewCops: enable
8
- TargetRubyVersion: 3.4
8
+ TargetRubyVersion: 4.0
9
9
  Exclude:
10
10
  - 'Rakefile'
11
11
  - 'bin/**/*'
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.4.6
1
+ 4.0.10
data/CHANGELOG.md CHANGED
@@ -1,4 +1,27 @@
1
- # splittable 0.0.9 (Oct 15, 2025)
1
+ # splittable 0.0.11 (Dec 06, 2026)
2
+
3
+ * **Ruby & Dependencies Update**
4
+ * Updated Ruby version to `4.0.10` across `.ruby-version`, CI workflow, and RuboCop config, with `required_ruby_version >= 4.0` in `splittable.gemspec` and `README.md`
5
+ * Relaxed `bigdecimal` dependency in `splittable.gemspec` (`>= 3.0, < 5.0`) to support BigDecimal 4.x
6
+ * Updated project gems in `Gemfile.lock` (including `bigdecimal` 4.1.3, `rubocop` 1.93.0, `rspec` 3.13.2, `rake` 13.4.2, and `simplecov` 1.3.2) and organized dev/test gems in `Gemfile`
7
+
8
+ * **Input Validation & Bug Fixes**
9
+ * Extracted shared `Splittable::InputValidator` to coerce numeric inputs (`String`, `Integer`, `Float`, `BigDecimal`) and reject `nil`, non-numeric, or non-finite values with `ArgumentError`
10
+ * Fixed `Splittable::Normalize` to coerce installments via `BigDecimal` before rounding (supporting `String` installments and avoiding binary float rounding issues)
11
+ * Added validation for `quantity` (must be a positive `Integer`) and `precision` (must be a non-negative `Integer`)
12
+
13
+ * **CI/CD & Tooling Improvements**
14
+ * Updated GitHub Actions (`actions/checkout@v7`), enabled `bundler-cache: true`, and simplified `ruby.yml` to run on Ruby `4.0.10` (`.ruby-version`)
15
+ * Migrated `publish_release.yml` to RubyGems Trusted Publishing (`rubygems/release-gem@v1` with OIDC) and automated release tagging
16
+ * Added `.github/dependabot.yml` for weekly `bundler` and `github-actions` updates
17
+ * Started `SimpleCov` before requiring `splittable` in `spec/spec_helper.rb` with `minimum_coverage 100` (54 examples, 0 failures, 100% line coverage)
18
+
19
+ *Marcelo Toledo*
20
+
21
+ ## splittable 0.0.10 (Sep 25, 2026)
22
+
23
+ * **Bump Versions**
24
+ * Fixed a vulnerability in libs
2
25
 
3
26
  * **Bug Fixes**
4
27
  * Fixed incorrect examples in README.md with mathematically accurate values
data/Gemfile CHANGED
@@ -4,12 +4,10 @@ source 'https://rubygems.org'
4
4
 
5
5
  gemspec
6
6
 
7
- gem 'bigdecimal'
8
- gem 'pry-byebug'
9
- gem 'rake'
10
- gem 'rspec'
11
-
12
7
  group :development, :test do
8
+ gem 'pry-byebug'
9
+ gem 'rake'
10
+ gem 'rspec'
13
11
  gem 'rubocop', require: false
14
12
  gem 'rubocop-performance', require: false
15
13
  gem 'rubocop-rake', require: false
data/Gemfile.lock CHANGED
@@ -1,91 +1,92 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- splittable (0.0.9)
5
- bigdecimal (~> 3.0)
4
+ splittable (0.0.11)
5
+ bigdecimal (>= 3.0, < 5.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
10
  ast (2.4.3)
11
- bigdecimal (3.3.1)
12
- byebug (12.0.0)
11
+ bigdecimal (4.1.3)
12
+ byebug (13.0.0)
13
+ reline (>= 0.6.0)
13
14
  coderay (1.1.3)
14
15
  diff-lcs (1.6.2)
15
- docile (1.4.1)
16
- json (2.15.1)
17
- language_server-protocol (3.17.0.5)
16
+ io-console (0.9.5)
17
+ json (3.2.0)
18
+ language_server-protocol (3.17.0.6)
18
19
  lint_roller (1.1.0)
19
20
  method_source (1.1.0)
20
- parallel (1.27.0)
21
- parser (3.3.9.0)
21
+ parallel (2.3.0)
22
+ parser (3.3.14.0)
22
23
  ast (~> 2.4.1)
23
24
  racc
24
- prism (1.5.2)
25
- pry (0.15.2)
25
+ prism (2.1.0)
26
+ prism (2.1.0-x86_64-linux-gnu)
27
+ pry (0.16.1)
26
28
  coderay (~> 1.1)
27
29
  method_source (~> 1.0)
28
- pry-byebug (3.11.0)
29
- byebug (~> 12.0)
30
- pry (>= 0.13, < 0.16)
30
+ reline (>= 0.6.0)
31
+ pry-byebug (3.12.0)
32
+ byebug (~> 13.0)
33
+ pry (>= 0.13, < 0.17)
31
34
  racc (1.8.1)
32
35
  rainbow (3.1.1)
33
- rake (13.3.0)
34
- regexp_parser (2.11.3)
35
- rspec (3.13.1)
36
+ rake (13.4.2)
37
+ regexp_parser (2.13.4)
38
+ reline (0.7.0)
39
+ io-console (~> 0.5)
40
+ rspec (3.13.2)
36
41
  rspec-core (~> 3.13.0)
37
42
  rspec-expectations (~> 3.13.0)
38
43
  rspec-mocks (~> 3.13.0)
39
- rspec-core (3.13.5)
44
+ rspec-core (3.13.7)
40
45
  rspec-support (~> 3.13.0)
41
- rspec-expectations (3.13.5)
46
+ rspec-expectations (3.13.6)
42
47
  diff-lcs (>= 1.2.0, < 2.0)
43
48
  rspec-support (~> 3.13.0)
44
- rspec-mocks (3.13.5)
49
+ rspec-mocks (3.13.9)
45
50
  diff-lcs (>= 1.2.0, < 2.0)
46
51
  rspec-support (~> 3.13.0)
47
- rspec-support (3.13.6)
48
- rubocop (1.81.1)
49
- json (~> 2.3)
52
+ rspec-support (3.13.8)
53
+ rubocop (1.93.0)
54
+ json (>= 2.3)
50
55
  language_server-protocol (~> 3.17.0.2)
51
56
  lint_roller (~> 1.1.0)
52
- parallel (~> 1.10)
57
+ parallel (>= 1.10)
53
58
  parser (>= 3.3.0.2)
54
59
  rainbow (>= 2.2.2, < 4.0)
55
- regexp_parser (>= 2.9.3, < 3.0)
56
- rubocop-ast (>= 1.47.1, < 2.0)
60
+ regexp_parser (>= 2.11.3, < 3.0)
61
+ rubocop-ast (>= 1.54.0, < 2.0)
57
62
  ruby-progressbar (~> 1.7)
58
63
  unicode-display_width (>= 2.4.0, < 4.0)
59
- rubocop-ast (1.47.1)
64
+ rubocop-ast (1.54.0)
65
+ ast (~> 2.4)
60
66
  parser (>= 3.3.7.2)
61
- prism (~> 1.4)
62
- rubocop-performance (1.26.0)
67
+ prism (>= 1.7)
68
+ racc
69
+ rubocop-performance (1.27.0)
63
70
  lint_roller (~> 1.1)
64
- rubocop (>= 1.75.0, < 2.0)
65
- rubocop-ast (>= 1.44.0, < 2.0)
71
+ rubocop (>= 1.89.0, < 2.0)
72
+ rubocop-ast (>= 1.47.1, < 2.0)
66
73
  rubocop-rake (0.7.1)
67
74
  lint_roller (~> 1.1)
68
75
  rubocop (>= 1.72.1)
69
- rubocop-rspec (3.7.0)
76
+ rubocop-rspec (3.11.0)
70
77
  lint_roller (~> 1.1)
71
- rubocop (~> 1.72, >= 1.72.1)
78
+ rubocop (~> 1.92)
72
79
  ruby-progressbar (1.13.0)
73
- simplecov (0.22.0)
74
- docile (~> 1.1)
75
- simplecov-html (~> 0.11)
76
- simplecov_json_formatter (~> 0.1)
77
- simplecov-html (0.13.2)
78
- simplecov_json_formatter (0.1.4)
79
- unicode-display_width (3.2.0)
80
- unicode-emoji (~> 4.1)
81
- unicode-emoji (4.1.0)
80
+ simplecov (1.3.2)
81
+ unicode-display_width (3.3.0)
82
+ unicode-emoji (~> 4.3)
83
+ unicode-emoji (4.3.0)
82
84
 
83
85
  PLATFORMS
84
86
  ruby
85
87
  x86_64-linux
86
88
 
87
89
  DEPENDENCIES
88
- bigdecimal
89
90
  pry-byebug
90
91
  rake
91
92
  rspec
@@ -97,4 +98,4 @@ DEPENDENCIES
97
98
  splittable!
98
99
 
99
100
  BUNDLED WITH
100
- 2.7.2
101
+ 4.1.1
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/splittable.svg)](https://badge.fury.io/rb/splittable)
4
4
  [![Ruby](https://github.com/m4rcelotoledo/splittable/workflows/Ruby/badge.svg?branch=master)](https://github.com/m4rcelotoledo/splittable/actions?query=workflow%3ARuby)
5
- [![Ruby Version](https://img.shields.io/badge/ruby-%3E%3D%203.4.6-red.svg)](https://www.ruby-lang.org/)
5
+ [![Ruby Version](https://img.shields.io/badge/ruby-%3E%3D%204.0-red.svg)](https://www.ruby-lang.org/)
6
6
  [![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
7
7
 
8
8
  ## 🎯 Problem Solved
@@ -1,12 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Splittable::Division
4
+ include Splittable::InputValidator
5
+
4
6
  def initialize(value:, quantity:, precision: 2)
5
- @precision = precision
6
- @value = BigDecimal(value, 15).truncate(precision)
7
- @quantity = BigDecimal(quantity.to_i, 15)
7
+ validate_precision!(precision)
8
+ validate_quantity!(quantity)
8
9
 
9
- check_quantity_as_positive_value!
10
+ @precision = precision
11
+ @value = coerce_decimal(value, 'value').truncate(precision)
12
+ @quantity = quantity
10
13
  end
11
14
 
12
15
  def call
@@ -21,7 +24,9 @@ class Splittable::Division
21
24
 
22
25
  attr_reader :value, :quantity, :precision
23
26
 
24
- def check_quantity_as_positive_value!
27
+ def validate_quantity!(quantity)
28
+ raise ArgumentError, 'quantity should be positive' if quantity.nil?
29
+ raise ArgumentError, 'quantity should be an integer' unless quantity.is_a?(Integer)
25
30
  return if quantity.positive?
26
31
 
27
32
  raise ArgumentError, 'quantity should be positive'
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Splittable::InputValidator
4
+ private
5
+
6
+ def coerce_decimal(raw_value, field_name)
7
+ raise ArgumentError, "#{field_name} must be numeric" if raw_value.nil?
8
+
9
+ decimal = BigDecimal(raw_value, 15)
10
+ raise ArgumentError, "#{field_name} must be numeric" unless decimal.finite?
11
+
12
+ decimal
13
+ rescue ArgumentError, TypeError
14
+ raise ArgumentError, "#{field_name} must be numeric"
15
+ end
16
+
17
+ def validate_precision!(precision)
18
+ return if precision.is_a?(Integer) && !precision.negative?
19
+
20
+ raise ArgumentError, 'precision should be a non-negative integer'
21
+ end
22
+ end
@@ -1,10 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Splittable::Normalize
4
+ include Splittable::InputValidator
5
+
4
6
  def initialize(value:, installments:, precision: 2)
5
- check_installments_validity!(installments)
6
- @value = BigDecimal(value, 15).truncate(precision)
7
- @installments = installments.map { |installment| BigDecimal(installment.round(precision), 15) }
7
+ validate_precision!(precision)
8
+ validate_installments!(installments)
9
+
10
+ @value = coerce_decimal(value, 'value').truncate(precision)
11
+ @installments = installments.map { |installment| coerce_decimal(installment, 'installment').round(precision) }
8
12
  end
9
13
 
10
14
  def call
@@ -19,7 +23,7 @@ class Splittable::Normalize
19
23
  attr_reader :value
20
24
  attr_accessor :installments
21
25
 
22
- def check_installments_validity!(installments)
26
+ def validate_installments!(installments)
23
27
  return if installments.is_a?(Array) && !installments.empty?
24
28
 
25
29
  raise ArgumentError, 'installments should be a non-empty array'
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Splittable
4
- VERSION = '0.0.9'
4
+ VERSION = '0.0.11'
5
5
  end
data/lib/splittable.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'splittable/version'
4
+ require 'splittable/input_validator'
4
5
  require 'splittable/division'
5
6
  require 'splittable/normalize'
6
7
  require 'bigdecimal/util'
data/splittable.gemspec CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
17
17
  'specified precision and attributing any difference to the first installment. ' \
18
18
  'Perfect for e-commerce payments, invoice distribution, and subscription billing.'
19
19
  spec.homepage = 'https://github.com/m4rcelotoledo/splittable'
20
- spec.required_ruby_version = Gem::Requirement.new('>= 3.4.6')
20
+ spec.required_ruby_version = Gem::Requirement.new('>= 4.0')
21
21
 
22
22
  spec.metadata['homepage_uri'] = spec.homepage
23
23
  spec.metadata['source_code_uri'] = 'https://github.com/m4rcelotoledo/splittable/tree/master'
@@ -34,5 +34,5 @@ Gem::Specification.new do |spec|
34
34
  spec.require_paths = ['lib']
35
35
 
36
36
  # Runtime dependencies
37
- spec.add_dependency 'bigdecimal', '~> 3.0'
37
+ spec.add_dependency 'bigdecimal', '>= 3.0', '< 5.0'
38
38
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: splittable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arthur Brandão
@@ -14,16 +14,22 @@ dependencies:
14
14
  name: bigdecimal
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5.0'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: '3.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.0'
27
33
  description: Splittable solves the common problem of dividing monetary values where
28
34
  the sum of rounded installments doesn't equal the original total. It ensures precise
29
35
  financial calculations by truncating values to the specified precision and attributing
@@ -40,6 +46,7 @@ files:
40
46
  - ".github/ISSUE_TEMPLATE/feature_request.md"
41
47
  - ".github/ISSUE_TEMPLATE/security_vulnerability.md"
42
48
  - ".github/PULL_REQUEST_TEMPLATE.md"
49
+ - ".github/dependabot.yml"
43
50
  - ".github/workflows/publish_release.yml"
44
51
  - ".github/workflows/ruby.yml"
45
52
  - ".gitignore"
@@ -58,6 +65,7 @@ files:
58
65
  - bin/setup
59
66
  - lib/splittable.rb
60
67
  - lib/splittable/division.rb
68
+ - lib/splittable/input_validator.rb
61
69
  - lib/splittable/normalize.rb
62
70
  - lib/splittable/version.rb
63
71
  - splittable.gemspec
@@ -77,14 +85,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
77
85
  requirements:
78
86
  - - ">="
79
87
  - !ruby/object:Gem::Version
80
- version: 3.4.6
88
+ version: '4.0'
81
89
  required_rubygems_version: !ruby/object:Gem::Requirement
82
90
  requirements:
83
91
  - - ">="
84
92
  - !ruby/object:Gem::Version
85
93
  version: '0'
86
94
  requirements: []
87
- rubygems_version: 3.6.9
95
+ rubygems_version: 4.0.20
88
96
  specification_version: 4
89
97
  summary: Split monetary values into equal installments with precise cent rounding.
90
98
  test_files: []