Skip to content

Commit f25fb3d

Browse files
olbrichCopilot
andauthored
Refactor for improved clarity and update Ruby version (#377)
Co-authored-by: olbrich <22176+olbrich@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
1 parent 089922f commit f25fb3d

14 files changed

Lines changed: 169 additions & 86 deletions

File tree

.github/workflows/tests.yml

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,6 @@ jobs:
3030
with:
3131
token: ${{ secrets.QLTY_COVERAGE_TOKEN }}
3232
files: coverage/.resultset.json
33-
# CodeClimate has become qlth.sh, this integration is currently broken.
34-
# coverage:
35-
# needs: test
36-
# runs-on: ubuntu-latest
37-
# env:
38-
# BUNDLE_WITHOUT: optional
39-
# steps:
40-
# - uses: actions/checkout@v6.0.1
41-
# - uses: ruby/setup-ruby@v1
42-
# with:
43-
# bundler-cache: true
44-
# - name: Publish code coverage
45-
# uses: paambaati/codeclimate-action@v9
46-
# env:
47-
# CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
48-
# with:
49-
# coverageCommand: bundle exec rake
5033

5134
yard:
5235
runs-on: ubuntu-latest

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
/spec/reports/
88
/tmp/
99
/bin/
10+
/vendor/bundle/
1011
# rspec failure tracking
1112
.rspec_status

.qlty/qlty.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,13 @@ threshold = 5
7777
[[source]]
7878
name = "default"
7979
default = true
80+
81+
[[plugin]]
82+
name = "rubocop"
83+
package_file = "Gemfile.qlty"
84+
package_filters = ["rubocop"]
85+
config_files = [".rubocop.yml", ".rubocop_todo.yml"]
86+
87+
[[plugin]]
88+
name = "reek"
89+
mode = "comment"

Gemfile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,14 @@ group :optional do
1010
gem "guard-rspec"
1111
gem "pry"
1212
gem "redcarpet", platform: :mri # redcarpet doesn't support jruby
13-
gem "rubocop"
14-
gem "rubocop-rake"
15-
gem "rubocop-rspec"
1613
gem "ruby-maven", platform: :jruby
1714
gem "ruby-prof", platform: :mri
1815
gem "simplecov-html"
1916
gem "solargraph"
2017
gem "terminal-notifier"
2118
gem "terminal-notifier-guard"
2219
gem "webrick"
20+
eval_gemfile("Gemfile.qlty")
2321
end
2422

2523
gem "bigdecimal"

Gemfile.lock

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
ruby-units (4.1.0)
4+
ruby-units (5.0.0)
55

66
GEM
77
remote: https://rubygems.org/
@@ -20,12 +20,10 @@ GEM
2020
reline (>= 0.3.8)
2121
diff-lcs (1.6.2)
2222
docile (1.4.1)
23-
e2mmap (0.1.0)
2423
erb (6.0.1)
2524
erb (6.0.1-java)
2625
ffi (1.17.2-arm64-darwin)
2726
ffi (1.17.2-java)
28-
ffi (1.17.2-x86_64-darwin)
2927
ffi (1.17.2-x86_64-linux-gnu)
3028
formatador (1.2.3)
3129
reline
@@ -74,13 +72,12 @@ GEM
7472
racc (~> 1.4)
7573
nokogiri (1.18.10-java)
7674
racc (~> 1.4)
77-
nokogiri (1.18.10-x86_64-darwin)
78-
racc (~> 1.4)
7975
nokogiri (1.18.10-x86_64-linux-gnu)
8076
racc (~> 1.4)
8177
notiffany (0.1.3)
8278
nenv (~> 0.1)
8379
shellany (~> 0.0)
80+
observer (0.1.2)
8481
ostruct (0.6.3)
8582
parallel (1.27.0)
8683
parser (3.3.10.0)
@@ -110,15 +107,17 @@ GEM
110107
rb-fsevent (0.11.2)
111108
rb-inotify (0.11.1)
112109
ffi (~> 1.0)
113-
rdoc (7.0.1)
110+
rbs (3.10.0)
111+
logger
112+
rdoc (7.0.2)
114113
erb
115114
psych (>= 4.0.0)
116115
tsort
117116
redcarpet (3.6.1)
118117
regexp_parser (2.11.3)
119118
reline (0.6.3)
120119
io-console (~> 0.5)
121-
reverse_markdown (2.1.1)
120+
reverse_markdown (3.0.1)
122121
nokogiri
123122
rexml (3.4.4)
124123
rspec (3.13.2)
@@ -134,7 +133,7 @@ GEM
134133
diff-lcs (>= 1.2.0, < 2.0)
135134
rspec-support (~> 3.13.0)
136135
rspec-support (3.13.6)
137-
rubocop (1.82.0)
136+
rubocop (1.82.1)
138137
json (~> 2.3)
139138
language_server-protocol (~> 3.17.0.2)
140139
lint_roller (~> 1.1.0)
@@ -167,21 +166,27 @@ GEM
167166
simplecov_json_formatter (~> 0.1)
168167
simplecov-html (0.13.2)
169168
simplecov_json_formatter (0.1.4)
170-
solargraph (0.48.0)
169+
solargraph (0.57.0)
171170
backport (~> 1.2)
172-
benchmark
173-
bundler (>= 1.17.2)
171+
benchmark (~> 0.4)
172+
bundler (~> 2.0)
174173
diff-lcs (~> 1.4)
175-
e2mmap
176-
jaro_winkler (~> 1.5)
174+
jaro_winkler (~> 1.6, >= 1.6.1)
177175
kramdown (~> 2.3)
178176
kramdown-parser-gfm (~> 1.1)
177+
logger (~> 1.6)
178+
observer (~> 0.1)
179+
ostruct (~> 0.6)
179180
parser (~> 3.0)
180-
reverse_markdown (>= 1.0.5, < 3)
181-
rubocop (>= 0.52)
181+
prism (~> 1.4)
182+
rbs (>= 3.6.1, <= 4.0.0.dev.4)
183+
reverse_markdown (~> 3.0)
184+
rubocop (~> 1.76)
182185
thor (~> 1.0)
183186
tilt (~> 2.0)
184187
yard (~> 0.9, >= 0.9.24)
188+
yard-activesupport-concern (~> 0.0)
189+
yard-solargraph (~> 0.1)
185190
spoon (0.0.6)
186191
ffi
187192
stringio (3.2.0)
@@ -195,17 +200,16 @@ GEM
195200
unicode-emoji (4.2.0)
196201
webrick (1.9.2)
197202
yard (0.9.38)
203+
yard-activesupport-concern (0.0.1)
204+
yard (>= 0.8)
205+
yard-solargraph (0.1.0)
206+
yard (~> 0.9)
198207

199208
PLATFORMS
200-
arm64-darwin-21
201-
arm64-darwin-22
202-
arm64-darwin-23
203-
arm64-darwin-24
204209
arm64-darwin-25
205210
java
206211
universal-java-11
207212
universal-java-18
208-
x86_64-darwin-19
209213
x86_64-linux
210214

211215
DEPENDENCIES
@@ -232,4 +236,4 @@ DEPENDENCIES
232236
yard
233237

234238
BUNDLED WITH
235-
4.0.2
239+
2.7.2

Gemfile.qlty

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# frozen_string_literal: true
2+
3+
source "https://rubygems.org"
4+
5+
# These are gems used by qlty to perform code quality checks.
6+
# They are installed by the qlty cli tool and are included for local development, but are not installed in CI.
7+
8+
gem "rubocop"
9+
gem "rubocop-rake"
10+
gem "rubocop-rspec"

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ manipulations to ensure an accurate result.
2525

2626
## Installation
2727

28+
This package requires Ruby 3.2 or later.
29+
2830
This package may be installed using:
2931

3032
```bash
@@ -52,6 +54,7 @@ unit = "1 mm".to_unit # convert string object
5254
unit = object.to_unit # convert any object using object.to_s
5355
unit = Unit.new('1/4 cup') # Rational number
5456
unit = Unit.new('1+1i mm') # Complex Number
57+
unit = Unit.new(scalar: 1.5, numerator: ["<meter>"], denominator: ["<second>"]) # keyword arguments
5558
```
5659

5760
### Rules

lib/ruby_units/configuration.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,15 @@ class Configuration
4242
# @return [Symbol] the format to use when generating output (:rational or :exponential) (default: :rational)
4343
attr_reader :format
4444

45-
def initialize
46-
self.format = :rational
47-
self.separator = true
45+
# Initialize configuration with keyword arguments
46+
#
47+
# @param separator [Boolean] whether to include a space between the scalar and the unit (default: true)
48+
# @param format [Symbol] the format to use when generating output (default: :rational)
49+
# @param _options [Hash] additional keyword arguments (ignored, for forward compatibility)
50+
# @return [Configuration] a new configuration instance
51+
def initialize(separator: true, format: :rational, **_options)
52+
self.separator = separator
53+
self.format = format
4854
end
4955

5056
# Use a space for the separator to use when generating output.

lib/ruby_units/definition.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,11 @@ def definition=(unit)
7979

8080
# is this definition for a prefix?
8181
# @return [Boolean]
82-
def prefix?
83-
kind == :prefix
84-
end
82+
def prefix? = kind == :prefix
8583

8684
# Is this definition the unity definition?
8785
# @return [Boolean]
88-
def unity?
89-
prefix? && scalar == 1
90-
end
86+
def unity? = prefix? && scalar == 1
9187

9288
# is this a base unit?
9389
# units are base units if the scalar is one, and the unit is defined in terms of itself.

0 commit comments

Comments
 (0)