midwire_common 1.1.1 → 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 +5 -5
- data/.github/mergeable.yml +43 -0
- data/.gitignore +23 -0
- data/.ruby-version +1 -1
- data/CLAUDE.md +95 -0
- data/Gemfile +2 -0
- data/README.md +8 -5
- data/Rakefile +3 -1
- data/docs/plans/2026-02-13-refinements-implementation.md +1494 -0
- data/docs/plans/2026-02-13-refinements-modernization-design.md +109 -0
- data/lib/midwire_common/all.rb +16 -1
- data/lib/midwire_common/array.rb +35 -45
- data/lib/midwire_common/data_file_cache.rb +6 -5
- data/lib/midwire_common/enumerable.rb +12 -8
- data/lib/midwire_common/file.rb +13 -1
- data/lib/midwire_common/float.rb +10 -3
- data/lib/midwire_common/hash.rb +94 -105
- data/lib/midwire_common/integer.rb +11 -0
- data/lib/midwire_common/number_behavior.rb +4 -2
- data/lib/midwire_common/rake_helper.rb +5 -3
- data/lib/midwire_common/rake_tasks.rb +2 -0
- data/lib/midwire_common/string.rb +76 -108
- data/lib/midwire_common/time.rb +10 -6
- data/lib/midwire_common/time_tool.rb +6 -2
- data/lib/midwire_common/version.rb +3 -1
- data/lib/midwire_common/yaml_setting.rb +4 -3
- data/lib/midwire_common.rb +8 -2
- data/lib/tasks/version.rake +21 -18
- data/midwire_common.gemspec +10 -13
- data/spec/lib/midwire_common/array_spec.rb +23 -23
- data/spec/lib/midwire_common/data_file_cache_spec.rb +14 -14
- data/spec/lib/midwire_common/enumerable_spec.rb +8 -4
- data/spec/lib/midwire_common/file/stat_spec.rb +8 -4
- data/spec/lib/midwire_common/float_spec.rb +7 -3
- data/spec/lib/midwire_common/hash_spec.rb +55 -24
- data/spec/lib/midwire_common/integer_spec.rb +11 -0
- data/spec/lib/midwire_common/rake_helper_spec.rb +6 -3
- data/spec/lib/midwire_common/string_spec.rb +46 -76
- data/spec/lib/midwire_common/time_spec.rb +19 -20
- data/spec/lib/midwire_common/time_tool_spec.rb +4 -2
- data/spec/lib/midwire_common/yaml_setting_spec.rb +8 -5
- data/spec/spec_helper.rb +18 -12
- metadata +29 -99
- data/Guardfile +0 -14
- data/lib/midwire_common/file/stat.rb +0 -11
- data/lib/midwire_common/fixnum.rb +0 -4
- data/spec/lib/midwire_common/fixnum_spec.rb +0 -15
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 0ec5ad4761d6f6a14b441e63ff1a18b1be5c2900b8c9302404b3321944953321
|
|
4
|
+
data.tar.gz: 42ac62ab72e3c3c78fcecbcf6da3f869f83e498766a907995bb43e78cdbdc79e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7dd67a8fee94b821bb360f3f19c2ab0af90665105abef667df040de666c50543e69619cff1d5af0f4c7759914c498aa8cd8841fbe22fd3d7b520e1ec6fe50df4
|
|
7
|
+
data.tar.gz: c8c5247f62f5fbed75400704646d0203220f6dc526bcaf6c7bbe607fd41cbf714d1e605124ba1f42e04a3641b3424857727c14f9178cb587763ae30ed9b91302
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
version: 2
|
|
2
|
+
mergeable:
|
|
3
|
+
- when: pull_request.*, pull_request_review.*
|
|
4
|
+
validate:
|
|
5
|
+
- do: title
|
|
6
|
+
# Enforce semantic release convention.
|
|
7
|
+
must_include:
|
|
8
|
+
regex: ^(feat|docs|chore|fix|refactor|test|style|perf)(\(\w+\))?:.+$
|
|
9
|
+
message: Semantic release conventions must be followed.
|
|
10
|
+
# All todo check boxes must be checked.
|
|
11
|
+
- do: description
|
|
12
|
+
must_exclude:
|
|
13
|
+
regex: \[ \]
|
|
14
|
+
message: There are incomplete TODO task(s) unchecked.
|
|
15
|
+
- do: approvals
|
|
16
|
+
min:
|
|
17
|
+
count: 1
|
|
18
|
+
or:
|
|
19
|
+
- required:
|
|
20
|
+
reviewers: [ jusx ]
|
|
21
|
+
- required:
|
|
22
|
+
reviewers: [ shine2lay ]
|
|
23
|
+
- do: or
|
|
24
|
+
# if the PR is a new feature or a fix, it must be logged in the changelog
|
|
25
|
+
validate:
|
|
26
|
+
- do: and
|
|
27
|
+
validate:
|
|
28
|
+
- do: title
|
|
29
|
+
must_include:
|
|
30
|
+
regex: ^(feat|fix)(\(\w+\))?:.+$
|
|
31
|
+
- do: changeset
|
|
32
|
+
must_include:
|
|
33
|
+
regex: 'docs/changelog.rst'
|
|
34
|
+
message: 'new features or fixes needed to be logged to the changelog'
|
|
35
|
+
- do: title
|
|
36
|
+
must_exclude:
|
|
37
|
+
regex: ^(feat|fix)(\(\w+\))?:.+$
|
|
38
|
+
message: 'new features or fixes needed to be logged to the changelog'
|
|
39
|
+
pass:
|
|
40
|
+
- do: merge
|
|
41
|
+
merge_method: 'squash'
|
|
42
|
+
- do: checks
|
|
43
|
+
status: 'success'
|
data/.gitignore
CHANGED
|
@@ -17,3 +17,26 @@ test/version_tmp
|
|
|
17
17
|
tmp
|
|
18
18
|
vendor/ruby
|
|
19
19
|
/vendor/
|
|
20
|
+
|
|
21
|
+
# Editor/IDE
|
|
22
|
+
.idea
|
|
23
|
+
.vscode
|
|
24
|
+
|
|
25
|
+
# Environment
|
|
26
|
+
.bash_profile
|
|
27
|
+
.bashrc
|
|
28
|
+
.profile
|
|
29
|
+
.zprofile
|
|
30
|
+
.zshrc
|
|
31
|
+
.gitconfig
|
|
32
|
+
.gitmodules
|
|
33
|
+
.ripgreprc
|
|
34
|
+
.mcp.json
|
|
35
|
+
.claude/
|
|
36
|
+
|
|
37
|
+
# Git internals (spurious)
|
|
38
|
+
/HEAD
|
|
39
|
+
/config
|
|
40
|
+
/hooks
|
|
41
|
+
/objects
|
|
42
|
+
/refs
|
data/.ruby-version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
3.4.8
|
data/CLAUDE.md
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## Project Overview
|
|
6
|
+
|
|
7
|
+
`midwire_common` is a Ruby gem providing lightweight extensions to Ruby core classes (String, Array, Hash, Float, Integer, Time, Enumerable) via **refinements**, plus utility classes (DataFileCache, YamlSetting, TimeTool, RakeHelper, BottomlessHash). Version 2.0.0. Requires Ruby >= 3.2.
|
|
8
|
+
|
|
9
|
+
## Commands
|
|
10
|
+
|
|
11
|
+
### Run all tests
|
|
12
|
+
```
|
|
13
|
+
bundle exec rspec
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
### Run a single test file
|
|
17
|
+
```
|
|
18
|
+
bundle exec rspec spec/lib/midwire_common/string_spec.rb
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### Run tests with coverage
|
|
22
|
+
```
|
|
23
|
+
COVERAGE=1 bundle exec rspec
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### Version bumping (prompts for CHANGELOG entry)
|
|
27
|
+
```
|
|
28
|
+
bundle exec rake version:bump_patch
|
|
29
|
+
bundle exec rake version:bump_minor
|
|
30
|
+
bundle exec rake version:bump_major
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Architecture
|
|
34
|
+
|
|
35
|
+
### Core Pattern: Refinements
|
|
36
|
+
|
|
37
|
+
Each class extension is a refinement module under `MidwireCommon` (e.g., `MidwireCommon::StringExtensions`). Consumers activate them per-file with `using`:
|
|
38
|
+
|
|
39
|
+
```ruby
|
|
40
|
+
require 'midwire_common/string'
|
|
41
|
+
using MidwireCommon::StringExtensions
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Or activate everything at once:
|
|
45
|
+
|
|
46
|
+
```ruby
|
|
47
|
+
require 'midwire_common/all'
|
|
48
|
+
using MidwireCommon::All
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Refinement modules use `refine ClassName do` for instance methods and `refine ClassName.singleton_class do` for class methods (e.g., `String.random`, `Time.timestamp`).
|
|
52
|
+
|
|
53
|
+
`NumberBehavior` is a shared module imported into Float and Integer refinements via `import_methods` (not `include`, which was removed from refinements in Ruby 3.2).
|
|
54
|
+
|
|
55
|
+
### Refinement Modules
|
|
56
|
+
|
|
57
|
+
| File | Module | Refines |
|
|
58
|
+
|------|--------|---------|
|
|
59
|
+
| `string.rb` | `StringExtensions` | `String`, `String.singleton_class` |
|
|
60
|
+
| `array.rb` | `ArrayExtensions` | `Array` |
|
|
61
|
+
| `hash.rb` | `HashExtensions` | `Hash` |
|
|
62
|
+
| `integer.rb` | `IntegerExtensions` | `Integer` |
|
|
63
|
+
| `float.rb` | `FloatExtensions` | `Float` |
|
|
64
|
+
| `enumerable.rb` | `EnumerableExtensions` | `Enumerable` |
|
|
65
|
+
| `time.rb` | `TimeExtensions` | `Time.singleton_class` |
|
|
66
|
+
| `file.rb` | `FileExtensions` | `File::Stat.singleton_class` |
|
|
67
|
+
|
|
68
|
+
### Loading
|
|
69
|
+
|
|
70
|
+
- `require 'midwire_common'` — loads namespace, version, and autoloads for utility classes
|
|
71
|
+
- `require 'midwire_common/all'` — loads all refinement modules and utility classes, defines `MidwireCommon::All`
|
|
72
|
+
- Individual files can be required separately (e.g., `require 'midwire_common/string'`)
|
|
73
|
+
|
|
74
|
+
### Utility Classes (namespaced under `MidwireCommon`)
|
|
75
|
+
|
|
76
|
+
- **BottomlessHash** — Hash subclass with auto-vivifying nested keys
|
|
77
|
+
- **DataFileCache** — file-based data caching with age tracking
|
|
78
|
+
- **YamlSetting** — YAML file-backed key/value configuration with lazy loading
|
|
79
|
+
- **TimeTool** — class-method-only utility for HH:MM:SS <-> seconds conversion
|
|
80
|
+
- **RakeHelper** — loads version-management rake tasks from `lib/tasks/`
|
|
81
|
+
|
|
82
|
+
### Rake Tasks
|
|
83
|
+
|
|
84
|
+
`lib/tasks/version.rake` provides `version:bump_patch`, `version:bump_minor`, `version:bump_major`. These tasks modify `lib/midwire_common/version.rb`, update the version string in `README.md`, and prepend to `CHANGELOG`. They warn when bumping on the `master` branch.
|
|
85
|
+
|
|
86
|
+
### Test Structure
|
|
87
|
+
|
|
88
|
+
Specs mirror `lib/` layout: `spec/lib/midwire_common/<name>_spec.rb`. Each spec file activates the refinements it needs with `using` at the top level. The spec helper includes `MidwireCommon` module at the top level for utility class access.
|
|
89
|
+
|
|
90
|
+
## Conventions
|
|
91
|
+
|
|
92
|
+
- Ruby version: specified in `.ruby-version` (currently 3.4.8), gemspec requires `>= 3.2`
|
|
93
|
+
- RSpec 3 with `--format documentation --color` (see `.rspec`), supports both `should` and `expect` syntax
|
|
94
|
+
- Tests run in random order
|
|
95
|
+
- Bang methods (`sanitize!`) follow Ruby convention of modifying in place
|
data/Gemfile
CHANGED
data/README.md
CHANGED
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://badge.fury.io/rb/midwire_common)
|
|
4
4
|
|
|
5
|
-
**Version:
|
|
5
|
+
**Version: 2.0.0**
|
|
6
6
|
|
|
7
7
|
A handy, light-weight Ruby library for Midwire development
|
|
8
8
|
|
|
9
|
+
Requires Ruby >= 3.2.
|
|
10
|
+
|
|
9
11
|
## Installation
|
|
10
12
|
|
|
11
13
|
Add this line to your application's Gemfile:
|
|
@@ -18,16 +20,17 @@ And then execute:
|
|
|
18
20
|
|
|
19
21
|
## Usage
|
|
20
22
|
|
|
21
|
-
### Ruby Class Extensions
|
|
23
|
+
### Ruby Class Extensions (Refinements)
|
|
22
24
|
|
|
23
|
-
|
|
25
|
+
As of 2.0.0, all class extensions use Ruby refinements instead of monkey-patching. Require the extensions, then activate them with `using`:
|
|
24
26
|
|
|
25
27
|
require 'midwire_common/all'
|
|
28
|
+
using MidwireCommon::All
|
|
26
29
|
|
|
27
|
-
... or include individual
|
|
30
|
+
... or include individual refinement modules:
|
|
28
31
|
|
|
29
32
|
require 'midwire_common/string'
|
|
30
|
-
|
|
33
|
+
using MidwireCommon::StringExtensions
|
|
31
34
|
|
|
32
35
|
### Rake Tasks
|
|
33
36
|
|
data/Rakefile
CHANGED