darthjee-core_ext 3.0.0 → 3.2.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 +4 -4
- data/.circleci/config.yml +10 -8
- data/.claude/agents/architect.md +41 -0
- data/.claude/agents/legacy.md +19 -0
- data/.claude/agents/ruby.md +31 -0
- data/.claude/agents/security.md +22 -0
- data/.claude/configuration/arcanum-repo-config.json +3 -0
- data/.claude/scripts/check_ruby.sh +8 -0
- data/.claude/settings.json +10 -0
- data/.github/commit_message_template-2.0.md +32 -0
- data/.github/commit_message_template.md +10 -0
- data/.github/copilot-instructions.md +1 -0
- data/.github/core_ext-usage.md +324 -0
- data/.github/pull_request_template.md +17 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +6 -5
- data/.rubocop_todo.yml +24 -11
- data/AGENTS.md +113 -0
- data/CLAUDE.md +1 -0
- data/Dockerfile +2 -2
- data/Gemfile +19 -12
- data/README.md +7 -8
- data/Rakefile +3 -0
- data/config/yardstick.yml +8 -36
- data/core_ext.gemspec +1 -1
- data/core_ext.jpg +0 -0
- data/docker-compose.yml +1 -1
- data/docs/agents/arcanum-split-issue.md +9 -0
- data/docs/agents/architecture.md +33 -0
- data/docs/agents/contributing.md +123 -0
- data/docs/agents/folder-structure.md +17 -0
- data/docs/agents/issue-enhancement.md +11 -0
- data/docs/agents/issues/.gitkeep +1 -0
- data/docs/agents/plans/.gitkeep +1 -0
- data/lib/darthjee/core_ext/array/hash_builder.rb +12 -0
- data/lib/darthjee/core_ext/hash/chain_fetcher.rb +22 -2
- data/lib/darthjee/core_ext/hash/deep_hash_constructor/setter.rb +12 -1
- data/lib/darthjee/core_ext/hash/deep_hash_constructor.rb +6 -1
- data/lib/darthjee/core_ext/hash/key_changer.rb +9 -0
- data/lib/darthjee/core_ext/hash/keys_sorter.rb +12 -0
- data/lib/darthjee/core_ext/hash/squasher.rb +8 -2
- data/lib/darthjee/core_ext/hash/transformable.rb +1 -0
- data/lib/darthjee/core_ext/hash/value_changer.rb +18 -0
- data/lib/darthjee/core_ext/numeric.rb +1 -1
- data/lib/darthjee/core_ext/time.rb +1 -0
- data/lib/darthjee/core_ext/version.rb +1 -1
- data/lib/darthjee/core_ext.rb +1 -0
- data/lib/darthjee.rb +1 -0
- data/scripts/bump_version.sh +62 -0
- data/spec/integration/readme/hash_spec.rb +2 -4
- data/spec/integration/yard/darthjee/core_ext/hash/changeable_spec.rb +2 -2
- data/spec/integration/yard/darthjee/core_ext/hash/value_changer_spec.rb +1 -1
- data/spec/integration/yard/darthjee/core_ext/object_spec.rb +1 -2
- data/spec/lib/darthjee/core_ext/hash/value_changer_spec.rb +8 -8
- data/spec/lib/object_spec.rb +1 -2
- data/spec/spec_helper.rb +6 -1
- metadata +27 -8
- data/mech.jpg +0 -0
data/AGENTS.md
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# GitHub Copilot Instructions for `darthjee/core_ext`
|
|
2
|
+
|
|
3
|
+
## Project Overview
|
|
4
|
+
|
|
5
|
+
`core_ext` is a Ruby gem that **adds methods to Ruby's standard objects** (core extensions). It extends built-in classes such as `Array`, `Hash`, `Symbol`, `Enumerable`, `Date`, `Object`, `Numeric`, and others with additional utility methods, while maintaining compatibility and predictable behavior.
|
|
6
|
+
|
|
7
|
+
- Gem name: `darthjee-core_ext`
|
|
8
|
+
- YARD docs: [rubydoc.info/gems/darthjee-core_ext](https://www.rubydoc.info/gems/darthjee-core_ext)
|
|
9
|
+
- Extensions live under `lib/darthjee/core_ext/`
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Language
|
|
14
|
+
|
|
15
|
+
- All code, comments, commit messages, pull request titles, PR descriptions, review comments, and documentation **must be written in English**.
|
|
16
|
+
- No exceptions: even if the author's primary language is not English, all contributions to this repository must use English.
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## Testing
|
|
21
|
+
|
|
22
|
+
- **Every new feature or bug fix must include tests.**
|
|
23
|
+
- Tests are written using RSpec and live under `spec/`.
|
|
24
|
+
- Follow the existing test structure: unit tests mirror the `lib/` directory layout under `spec/lib/`.
|
|
25
|
+
- If a file does not have a corresponding spec file and **intentionally** has no tests (e.g., it is a pure re-export or namespace file), it must be listed in `config/check_specs.yml` under the `ignore:` key.
|
|
26
|
+
- Do **not** add files to `config/check_specs.yml` as a shortcut to avoid writing tests. Only files that genuinely cannot or should not have direct tests belong there.
|
|
27
|
+
- Run the full test suite before opening a PR: `bundle exec rspec`.
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## Documentation
|
|
32
|
+
|
|
33
|
+
- All public methods must be documented using **YARD** syntax.
|
|
34
|
+
- Use `@param`, `@return`, `@example`, and `@raise` tags where applicable.
|
|
35
|
+
- Include at least one `@example` block for methods that demonstrate non-trivial behavior.
|
|
36
|
+
- Keep documentation close to the code (inline in the source file).
|
|
37
|
+
- Example:
|
|
38
|
+
|
|
39
|
+
```ruby
|
|
40
|
+
# Converts the hash keys to camel case.
|
|
41
|
+
#
|
|
42
|
+
# @param [Symbol] type the case type (:lower or :upper)
|
|
43
|
+
# @return [Hash] a new hash with camel-cased keys
|
|
44
|
+
# @example
|
|
45
|
+
# { my_key: 1 }.camelize_keys #=> { myKey: 1 }
|
|
46
|
+
def camelize_keys(type = :lower)
|
|
47
|
+
# ...
|
|
48
|
+
end
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## Design Principles
|
|
54
|
+
|
|
55
|
+
### Single Responsibility
|
|
56
|
+
|
|
57
|
+
- Classes and methods should have **one reason to change** (Single Responsibility Principle).
|
|
58
|
+
- Prefer small, focused methods. If a method is doing more than one thing, extract the extra responsibility into a helper method or a collaborator class.
|
|
59
|
+
- Follow the approach described by **Sandi Metz** in *99 Bottles of OOP*:
|
|
60
|
+
- Prefer simple, obvious code over clever code.
|
|
61
|
+
- Let the tests drive refactoring: make it work, make it right, make it fast.
|
|
62
|
+
- Use small objects that collaborate through messages.
|
|
63
|
+
- Avoid premature abstraction; introduce it only when duplication demands it.
|
|
64
|
+
|
|
65
|
+
### Law of Demeter
|
|
66
|
+
|
|
67
|
+
- Avoid **Law of Demeter violations**: do not chain method calls across multiple object boundaries (e.g., `a.b.c.d`).
|
|
68
|
+
- Instead, delegate behavior closer to the data: expose a method on the intermediate object, or use a helper that encapsulates the traversal.
|
|
69
|
+
- Code that violates the Law of Demeter increases coupling and makes refactoring harder.
|
|
70
|
+
|
|
71
|
+
```ruby
|
|
72
|
+
# Avoid
|
|
73
|
+
user.address.city.upcase
|
|
74
|
+
|
|
75
|
+
# Prefer
|
|
76
|
+
user.city_upcased
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### General Style
|
|
80
|
+
|
|
81
|
+
- Prefer composition over inheritance.
|
|
82
|
+
- Keep class hierarchies shallow.
|
|
83
|
+
- Avoid monkey-patching outside of the intended extension pattern of this gem.
|
|
84
|
+
- New core extensions must be clearly scoped to a specific Ruby class and added in the appropriate file under `lib/darthjee/core_ext/`.
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
## Pull Request Guidelines
|
|
89
|
+
|
|
90
|
+
- PR titles and descriptions must be in **English**.
|
|
91
|
+
- Every PR should include:
|
|
92
|
+
- A clear description of what changed and why.
|
|
93
|
+
- References to any related issues.
|
|
94
|
+
- Confirmation that tests pass locally.
|
|
95
|
+
- Reviewers should check that:
|
|
96
|
+
- New code is covered by tests.
|
|
97
|
+
- Documentation follows YARD conventions.
|
|
98
|
+
- Design principles (single responsibility, Demeter) are respected.
|
|
99
|
+
- No file was added to `config/check_specs.yml` without a valid justification.
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
## Agent Documentation
|
|
104
|
+
|
|
105
|
+
| Document | Description |
|
|
106
|
+
|----------|-------------|
|
|
107
|
+
| [Folder Structure](docs/agents/folder-structure.md) | Top-level directory layout and the role of each folder. |
|
|
108
|
+
| [Architecture](docs/agents/architecture.md) | Source layout and design of the gem. |
|
|
109
|
+
| [Contributing](docs/agents/contributing.md) | Commit guidelines, PR standards, code organization, and refactoring rules. |
|
|
110
|
+
|
|
111
|
+
## Commit Attribution
|
|
112
|
+
|
|
113
|
+
Commit co-author trailers follow arcanum's resolved `git.omit_model_coauthor` and `git.remove_coauthors` config (check them with `/arcanum-check-config`); this overrides Claude Code's own attribution reminder for every commit, including ones written by hand.
|
data/CLAUDE.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
See [AGENTS.md](AGENTS.md) for project instructions.
|
data/Dockerfile
CHANGED
data/Gemfile
CHANGED
|
@@ -5,15 +5,22 @@ source 'https://rubygems.org'
|
|
|
5
5
|
# Specify your gem's dependencies in credential_builder.gemspec
|
|
6
6
|
gemspec
|
|
7
7
|
|
|
8
|
-
gem 'bundler',
|
|
9
|
-
gem 'pry',
|
|
10
|
-
gem 'pry-nav',
|
|
11
|
-
gem 'rake',
|
|
12
|
-
gem '
|
|
13
|
-
gem '
|
|
14
|
-
gem '
|
|
15
|
-
gem '
|
|
16
|
-
gem '
|
|
17
|
-
gem '
|
|
18
|
-
gem '
|
|
19
|
-
gem '
|
|
8
|
+
gem 'bundler', '>= 4.0.24'
|
|
9
|
+
gem 'pry', '0.14.2'
|
|
10
|
+
gem 'pry-nav', '1.0.0'
|
|
11
|
+
gem 'rake', '13.4.2'
|
|
12
|
+
gem 'reek', '6.5.0'
|
|
13
|
+
gem 'rspec', '3.13.2'
|
|
14
|
+
gem 'rspec-core', '3.13.7'
|
|
15
|
+
gem 'rspec-expectations', '3.13.6'
|
|
16
|
+
gem 'rspec-mocks', '3.13.9'
|
|
17
|
+
gem 'rspec-support', '3.13.8'
|
|
18
|
+
gem 'rubocop', '1.92.2'
|
|
19
|
+
gem 'rubocop-rake', '0.7.1'
|
|
20
|
+
gem 'rubocop-rspec', '3.10.2'
|
|
21
|
+
gem 'rubycritic', '5.0.0'
|
|
22
|
+
gem 'simplecov', '0.22.0'
|
|
23
|
+
gem 'simplecov-html', '0.13.2'
|
|
24
|
+
gem 'simplecov-lcov', '0.9.0'
|
|
25
|
+
gem 'yard', '0.9.45'
|
|
26
|
+
gem 'yardstick', '0.9.9'
|
data/README.md
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
Darthjee/CoreExt
|
|
2
2
|
========
|
|
3
|
-
|
|
4
|
-
[](https://codeclimate.com/github/darthjee/core_ext)
|
|
5
|
-
[](https://codeclimate.com/github/darthjee/core_ext/coverage)
|
|
6
|
-
[](https://codeclimate.com/github/darthjee/core_ext)
|
|
3
|
+
[](https://dl.circleci.com/status-badge/redirect/gh/darthjee/core_ext/tree/main)
|
|
7
4
|
[](https://badge.fury.io/rb/darthjee-core_ext)
|
|
5
|
+
[](https://app.codacy.com/gh/darthjee/core_ext/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
|
|
6
|
+
[](https://app.codacy.com/gh/darthjee/core_ext/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_coverage)
|
|
8
7
|
|
|
9
|
-

|
|
10
9
|
|
|
11
10
|
Yard Documentation
|
|
12
11
|
-------------------
|
|
13
|
-
[https://www.rubydoc.info/gems/darthjee-core_ext/3.
|
|
12
|
+
[https://www.rubydoc.info/gems/darthjee-core_ext/3.2.0](https://www.rubydoc.info/gems/darthjee-core_ext/3.2.0)
|
|
14
13
|
|
|
15
|
-
Current Release
|
|
14
|
+
**Current Release**: [3.2.0](https://github.com/darthjee/core_ext/tree/3.2.0)
|
|
16
15
|
|
|
17
|
-
|
|
16
|
+
**Next release**: [3.3.0](https://github.com/darthjee/core_ext/compare/3.2.0...main)
|
|
18
17
|
|
|
19
18
|
# Usage
|
|
20
19
|
This project adds some new methods to the core ruby classes
|
data/Rakefile
CHANGED
data/config/yardstick.yml
CHANGED
|
@@ -19,24 +19,14 @@ rules:
|
|
|
19
19
|
ReturnTag:
|
|
20
20
|
enabled: true
|
|
21
21
|
exclude:
|
|
22
|
-
- Darthjee::CoreExt::Array::HashBuilder#
|
|
23
|
-
- Darthjee::CoreExt::
|
|
24
|
-
- Darthjee::CoreExt::
|
|
25
|
-
- Darthjee::CoreExt::
|
|
26
|
-
- Darthjee::CoreExt::Hash::
|
|
27
|
-
- Darthjee::CoreExt::Hash::
|
|
28
|
-
- Darthjee::CoreExt::Hash::
|
|
29
|
-
- Darthjee::CoreExt::Hash::
|
|
30
|
-
- Darthjee::CoreExt::Hash::DeepHashConstructor::Setter#hash
|
|
31
|
-
- Darthjee::CoreExt::Hash::DeepHashConstructor::Setter#base_key
|
|
32
|
-
- Darthjee::CoreExt::Hash::DeepHashConstructor::Setter#key
|
|
33
|
-
- Darthjee::CoreExt::Hash::KeyChanger#hash
|
|
34
|
-
- Darthjee::CoreExt::Hash::KeysSorter#hash
|
|
35
|
-
- Darthjee::CoreExt::Hash::KeysSorter#recursive
|
|
36
|
-
- Darthjee::CoreExt::Hash::Squasher#joiner
|
|
37
|
-
- Darthjee::CoreExt::Hash::ValueChanger#recursive
|
|
38
|
-
- Darthjee::CoreExt::Hash::ValueChanger#skip_inner
|
|
39
|
-
- Darthjee::CoreExt::Hash::ValueChanger#block
|
|
22
|
+
- Darthjee::CoreExt::Array::HashBuilder#initialize
|
|
23
|
+
- Darthjee::CoreExt::Hash::ChainFetcher#initialize
|
|
24
|
+
- Darthjee::CoreExt::Hash::KeyChanger#initialize
|
|
25
|
+
- Darthjee::CoreExt::Hash::KeysSorter#initialize
|
|
26
|
+
- Darthjee::CoreExt::Hash::DeepHashConstructor#initialize
|
|
27
|
+
- Darthjee::CoreExt::Hash::DeepHashConstructor::Setter#initialize
|
|
28
|
+
- Darthjee::CoreExt::Hash::Squasher#initialize
|
|
29
|
+
- Darthjee::CoreExt::Hash::ValueChanger#initialize
|
|
40
30
|
Summary::Presence:
|
|
41
31
|
enabled: true
|
|
42
32
|
exclude:
|
|
@@ -48,24 +38,6 @@ rules:
|
|
|
48
38
|
- Darthjee::CoreExt::Hash::DeepHashConstructor::Setter#initialize
|
|
49
39
|
- Darthjee::CoreExt::Hash::KeysSorter#initialize
|
|
50
40
|
- Darthjee::CoreExt::Hash::Squasher#initialize
|
|
51
|
-
- Darthjee::CoreExt::Array::HashBuilder#values
|
|
52
|
-
- Darthjee::CoreExt::Array::HashBuilder#keys
|
|
53
|
-
- Darthjee::CoreExt::Array::HashBuilder#values=
|
|
54
|
-
- Darthjee::CoreExt::Array::HashBuilder#keys=
|
|
55
|
-
- Darthjee::CoreExt::Hash::ChainFetcher#hash
|
|
56
|
-
- Darthjee::CoreExt::Hash::ChainFetcher#keys
|
|
57
|
-
- Darthjee::CoreExt::Hash::ChainFetcher#block
|
|
58
|
-
- Darthjee::CoreExt::Hash::DeepHashConstructor#separator
|
|
59
|
-
- Darthjee::CoreExt::Hash::DeepHashConstructor::Setter#hash
|
|
60
|
-
- Darthjee::CoreExt::Hash::DeepHashConstructor::Setter#base_key
|
|
61
|
-
- Darthjee::CoreExt::Hash::DeepHashConstructor::Setter#key
|
|
62
|
-
- Darthjee::CoreExt::Hash::KeyChanger#hash
|
|
63
|
-
- Darthjee::CoreExt::Hash::KeysSorter#hash
|
|
64
|
-
- Darthjee::CoreExt::Hash::KeysSorter#recursive
|
|
65
|
-
- Darthjee::CoreExt::Hash::Squasher#joiner
|
|
66
|
-
- Darthjee::CoreExt::Hash::ValueChanger#recursive
|
|
67
|
-
- Darthjee::CoreExt::Hash::ValueChanger#skip_inner
|
|
68
|
-
- Darthjee::CoreExt::Hash::ValueChanger#block
|
|
69
41
|
Summary::Length:
|
|
70
42
|
enabled: true
|
|
71
43
|
exclude: []
|
data/core_ext.gemspec
CHANGED
data/core_ext.jpg
ADDED
|
Binary file
|
data/docker-compose.yml
CHANGED
|
@@ -23,7 +23,7 @@ services:
|
|
|
23
23
|
command: /bin/bash -c 'rspec && yard && rake yardstick_measure && rake verify_measurements'
|
|
24
24
|
|
|
25
25
|
core_ext_circleci:
|
|
26
|
-
image: darthjee/
|
|
26
|
+
image: darthjee/circleci_ruby_3412:1.0.0
|
|
27
27
|
container_name: core_ext_circleci
|
|
28
28
|
command: /bin/bash
|
|
29
29
|
volumes:
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Arcanum Split Issue
|
|
2
|
+
|
|
3
|
+
A checklist of concerns to consider when splitting a broad issue into sub-issues via `/arcanum-split-issue`. Not exhaustive — adjust or extend the list for this project's needs.
|
|
4
|
+
|
|
5
|
+
- **Sub-issue granularity** — is each sub-issue independently workable, or does it still depend on another sub-issue landing first?
|
|
6
|
+
- **Standalone clarity** — does each sub-issue stand on its own, without requiring the reader to have the parent issue open to understand it?
|
|
7
|
+
- **Shared contracts** — interfaces, schemas, or config keys touched by more than one sub-issue, and who owns getting them right first.
|
|
8
|
+
- **Sequencing** — is there a natural order sub-issues should be implemented/merged in, or can they proceed in parallel?
|
|
9
|
+
- **Responsible agents** — which specialist agent(s) each sub-issue is likely to fall to.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Architecture
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
`darthjee-core_ext` is a Ruby gem that adds utility methods to Ruby's built-in classes. Each extension is scoped to one core class and lives in its own file, so a consumer can require only what they need.
|
|
6
|
+
|
|
7
|
+
## Source Code Layout
|
|
8
|
+
|
|
9
|
+
All source lives under `lib/darthjee/core_ext/`. `lib/darthjee.rb` is the entry point.
|
|
10
|
+
|
|
11
|
+
- `array.rb`, `class.rb`, `date.rb`, `enumerable.rb`, `hash.rb`, `math.rb`, `numeric.rb`, `object.rb`, `symbol.rb` and `time.rb` each extend the matching core class.
|
|
12
|
+
- `version.rb` holds the gem version.
|
|
13
|
+
|
|
14
|
+
### `array/`
|
|
15
|
+
|
|
16
|
+
`HashBuilder`, a helper behind the `Array` extension that builds hashes.
|
|
17
|
+
|
|
18
|
+
### `hash/`
|
|
19
|
+
|
|
20
|
+
Collaborators for the `Hash` extension, one responsibility per class:
|
|
21
|
+
|
|
22
|
+
- Key and value changing: `key_changer`, `value_changer`, `key_changeable`, `changeable`
|
|
23
|
+
- Camel-casing: `cameliazable`
|
|
24
|
+
- Sorting keys: `keys_sorter`
|
|
25
|
+
- Chained fetching: `chain_fetcher`
|
|
26
|
+
- Squashing nested hashes: `squasher`
|
|
27
|
+
- Transforming and transposing: `transformable`, `transposeable`
|
|
28
|
+
- Deep construction: `deep_hash_constructor`
|
|
29
|
+
|
|
30
|
+
## Conventions
|
|
31
|
+
|
|
32
|
+
- Public methods are documented with YARD. The Yardstick config is in `config/`.
|
|
33
|
+
- Specs mirror `lib/` under `spec/lib/`. Files without specs must be listed in `config/check_specs.yml`.
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
## Commit Guidelines
|
|
4
|
+
|
|
5
|
+
- **Atomic and Unitary:** Each commit must represent a single logical change.
|
|
6
|
+
*Example:*
|
|
7
|
+
- Good: `Add Hash#squash method`
|
|
8
|
+
- Bad: `Add Hash#squash and refactor KeyChanger`
|
|
9
|
+
- **No Unrelated Changes:** Do not mix unrelated changes in the same commit.
|
|
10
|
+
- **Separate Refactoring:** Whenever possible, separate refactoring commits from new feature or bugfix commits.
|
|
11
|
+
|
|
12
|
+
## Pull Requests
|
|
13
|
+
|
|
14
|
+
- **Descriptive Summary:** Every PR must include a clear and descriptive summary of its purpose and changes.
|
|
15
|
+
- **PR Description Files:** If a description cannot be provided directly in the PR, generate a file with the PR description (e.g., `docs/agents/issues/<pr_number>_description.md`), but do not commit this file.
|
|
16
|
+
|
|
17
|
+
## Definition of Done for PRs
|
|
18
|
+
|
|
19
|
+
A PR is considered complete when:
|
|
20
|
+
|
|
21
|
+
- The stated objective has been achieved.
|
|
22
|
+
- All tests are passing.
|
|
23
|
+
- Linting passes without errors.
|
|
24
|
+
- Code coverage is as high as reasonably possible.
|
|
25
|
+
- Code is not overly complex:
|
|
26
|
+
- Classes and methods should have clear, focused responsibilities.
|
|
27
|
+
- If a class or method is taking on too many responsibilities, refactor to simplify.
|
|
28
|
+
- Methods should be small and do exactly one thing. If a method is growing, extract parts into private helper methods or separate classes.
|
|
29
|
+
- *Example (pseudo-code):*
|
|
30
|
+
|
|
31
|
+
```ruby
|
|
32
|
+
# Good: each method does one thing
|
|
33
|
+
class Worker
|
|
34
|
+
def fetch_job; end
|
|
35
|
+
def process_job(job); end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Bad: method does too much
|
|
39
|
+
class Worker
|
|
40
|
+
def run
|
|
41
|
+
fetch_job
|
|
42
|
+
process_job
|
|
43
|
+
send_metrics
|
|
44
|
+
cleanup
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
- This requirement applies primarily to source code. For specs, refactor only if there is excessive duplication.
|
|
50
|
+
|
|
51
|
+
### CI Checks
|
|
52
|
+
|
|
53
|
+
Before a PR is considered complete, all CI checks must pass locally. The project has a single Ruby codebase, so every code change runs both CircleCI jobs (`.circleci/config.yml`):
|
|
54
|
+
|
|
55
|
+
| CircleCI job | Local command |
|
|
56
|
+
| --- | --- |
|
|
57
|
+
| `test` | `bundle exec rspec` |
|
|
58
|
+
| `checks` | `bundle exec rubocop` |
|
|
59
|
+
| `checks` | `bundle exec rake verify_measurements` (YARD documentation coverage; run `bundle exec rake yardstick_measure` first if needed) |
|
|
60
|
+
| `checks` | `PROJECT=darthjee-core_ext scripts/check_readme.sh` (README must reference the current version's YARD docs) |
|
|
61
|
+
| `checks` | `scripts/rubycritic.sh` (RubyCritic on changed `lib/` files) |
|
|
62
|
+
| `checks` | `check_specs` (every `lib/` file needs a spec unless listed in `config/check_specs.yml`) |
|
|
63
|
+
|
|
64
|
+
Commands can also be run inside Docker via `docker-compose run core_ext_circleci`, `make dev` or `make ci`.
|
|
65
|
+
|
|
66
|
+
This same process must be followed when **planning how to resolve an issue**: include a final step in the plan that lists the CI commands to run before opening a PR.
|
|
67
|
+
|
|
68
|
+
## Code Organization
|
|
69
|
+
|
|
70
|
+
### File Responsibility: Class Declarers vs Scripts
|
|
71
|
+
|
|
72
|
+
Every source file under `lib/` must define one or more classes or modules and must not execute logic or cause side effects at load time. The only extension point is reopening/including into core classes, which is the purpose of this gem.
|
|
73
|
+
|
|
74
|
+
### File Naming
|
|
75
|
+
|
|
76
|
+
Files use `snake_case.rb` and mirror the constant they define (`KeyChanger` in `key_changer.rb`). Specs mirror `lib/` under `spec/lib/` with a `_spec.rb` suffix. Core extensions go in `lib/darthjee/core_ext/<class>.rb`; collaborators go in a sibling folder named after the class (e.g. `hash/`).
|
|
77
|
+
|
|
78
|
+
### Method Order: Public Before Private
|
|
79
|
+
|
|
80
|
+
Public methods are declared before `private` ones; private methods are implementation helpers placed at the end of the class.
|
|
81
|
+
|
|
82
|
+
```ruby
|
|
83
|
+
# Good
|
|
84
|
+
class Worker
|
|
85
|
+
def run
|
|
86
|
+
prepare
|
|
87
|
+
execute
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
private
|
|
91
|
+
|
|
92
|
+
def prepare; end
|
|
93
|
+
def execute; end
|
|
94
|
+
end
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Dependency Injection
|
|
98
|
+
|
|
99
|
+
Classes receive their dependencies (data, collaborators) as constructor arguments and never load files or read environment variables themselves. This keeps every class independently testable.
|
|
100
|
+
|
|
101
|
+
```ruby
|
|
102
|
+
# Good
|
|
103
|
+
class Router
|
|
104
|
+
def initialize(data)
|
|
105
|
+
@data = data
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# Bad
|
|
110
|
+
class Router
|
|
111
|
+
def build
|
|
112
|
+
data = YAML.load_file('./data.yml')
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Refactoring Guidelines
|
|
118
|
+
|
|
119
|
+
When refactoring, aim to:
|
|
120
|
+
|
|
121
|
+
- **Reduce Code Duplication:** move repeated spec setup into `let` blocks or shared helpers.
|
|
122
|
+
- **Keep Classes Focused:** extract responsibilities into collaborator classes (see `lib/darthjee/core_ext/hash/`).
|
|
123
|
+
- **Follow the Law of Demeter:** avoid chains like `a.b.c.d`.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Folder Structure
|
|
2
|
+
|
|
3
|
+
## Project Root
|
|
4
|
+
|
|
5
|
+
| Directory / File | Description |
|
|
6
|
+
|------------------|-------------|
|
|
7
|
+
| `lib/` | Gem source code (`lib/darthjee/core_ext/`). |
|
|
8
|
+
| `spec/` | RSpec tests: `lib/` mirrors the source layout, `integration/` holds README and YARD checks, `support/` holds helpers. |
|
|
9
|
+
| `config/` | Tooling config: `check_specs.yml` (files exempt from needing specs), RubyCritic and Yardstick settings. |
|
|
10
|
+
| `scripts/` | Helper shell scripts (`check_readme.sh`, `rubycritic.sh`). |
|
|
11
|
+
| `.circleci/` | CircleCI pipeline. |
|
|
12
|
+
| `.github/` | Copilot pointer, PR template and commit message templates. |
|
|
13
|
+
| `docs/agents/` | Documentation, issues and plans for AI agents. |
|
|
14
|
+
| `*_README.md` | Per-class usage docs (Array, Class, Date, Enumerable, Hash, Math, Object, Symbol), linked from `README.md`. |
|
|
15
|
+
| `core_ext.gemspec`, `Gemfile`, `Rakefile` | Gem packaging and dependencies. |
|
|
16
|
+
| `Dockerfile`, `docker-compose.yml`, `Makefile` | Dev and CI container environment (`make dev`, `make ci`). |
|
|
17
|
+
| `.rubocop*.yml`, `.reek.yml` | Lint and code-smell configuration. |
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Issue Enhancement
|
|
2
|
+
|
|
3
|
+
A checklist of concerns to consider when fleshing out a vague issue idea (tagged `Idea`/`Writting`) before it reaches the `Created` stage. Not exhaustive — adjust or extend the list for this project's needs.
|
|
4
|
+
|
|
5
|
+
- **Scope boundaries** — what's explicitly in scope and what's explicitly out.
|
|
6
|
+
- **Alternative solutions** — other ways to solve the same problem, and why this one was chosen.
|
|
7
|
+
- **Edge cases** — inputs, states, or timing the happy path doesn't cover.
|
|
8
|
+
- **Backward compatibility** — whether this breaks existing behavior, data, or integrations.
|
|
9
|
+
- **Testing strategy** — how the change will be verified.
|
|
10
|
+
- **Performance & security considerations** — anything relevant to load, latency, or attack surface.
|
|
11
|
+
- **Obsolescence** — whether the method (or the one being changed) is obsolete because Ruby now provides an equivalent, and if so, whether to deprecate, alias or remove it.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -52,6 +52,18 @@ module Darthjee
|
|
|
52
52
|
|
|
53
53
|
attr_reader :values, :keys
|
|
54
54
|
|
|
55
|
+
# @method values
|
|
56
|
+
# @api private
|
|
57
|
+
# @private
|
|
58
|
+
# Returns the values of the hash to be built
|
|
59
|
+
# @return [::Array] values of the hash to be built
|
|
60
|
+
|
|
61
|
+
# @method keys
|
|
62
|
+
# @api private
|
|
63
|
+
# @private
|
|
64
|
+
# Returns the keys of the hash to be built
|
|
65
|
+
# @return [::Array] keys of the hash to be built
|
|
66
|
+
|
|
55
67
|
# @private
|
|
56
68
|
#
|
|
57
69
|
# Fixes the size of values array to match keys array size
|
|
@@ -11,6 +11,9 @@ module Darthjee
|
|
|
11
11
|
#
|
|
12
12
|
# @see Darthjee::CoreExt::Hash#chain_fetch
|
|
13
13
|
class ChainFetcher
|
|
14
|
+
# @param [::Hash] hash Hash to fetch from
|
|
15
|
+
# @param [Array] keys List of keys to fetch in chain
|
|
16
|
+
# @param [Proc] block Block to call in case of missing key
|
|
14
17
|
def initialize(hash, *keys, &block)
|
|
15
18
|
@hash = hash
|
|
16
19
|
@keys = keys
|
|
@@ -21,7 +24,7 @@ module Darthjee
|
|
|
21
24
|
#
|
|
22
25
|
# @example (see Darthjee::CoreExt::Hash#chain_fetch)
|
|
23
26
|
#
|
|
24
|
-
# @return [Object] value fetched from
|
|
27
|
+
# @return [Object] value fetched from hash
|
|
25
28
|
def fetch
|
|
26
29
|
return fetch_with_block if block.present?
|
|
27
30
|
|
|
@@ -30,9 +33,26 @@ module Darthjee
|
|
|
30
33
|
|
|
31
34
|
private
|
|
32
35
|
|
|
33
|
-
# @private
|
|
34
36
|
attr_reader :hash, :keys, :block
|
|
35
37
|
|
|
38
|
+
# @method hash
|
|
39
|
+
# @api private
|
|
40
|
+
# @private
|
|
41
|
+
# Returns the hash to fetch from
|
|
42
|
+
# @return [::Hash] hash to fetch from
|
|
43
|
+
|
|
44
|
+
# @method keys
|
|
45
|
+
# @api private
|
|
46
|
+
# @private
|
|
47
|
+
# Returns the list of keys to fetch in chain
|
|
48
|
+
# @return [::Array] list of keys to fetch in chain
|
|
49
|
+
|
|
50
|
+
# @method block
|
|
51
|
+
# @api private
|
|
52
|
+
# @private
|
|
53
|
+
# Returns the block to call in case of missing key
|
|
54
|
+
# @return [Proc] block to call in case of missing key
|
|
55
|
+
|
|
36
56
|
# @private
|
|
37
57
|
#
|
|
38
58
|
# Perform chain fetch when block is given
|
|
@@ -63,9 +63,20 @@ module Darthjee
|
|
|
63
63
|
|
|
64
64
|
private
|
|
65
65
|
|
|
66
|
-
# @private
|
|
67
66
|
attr_reader :hash, :base_key
|
|
68
67
|
|
|
68
|
+
# @method hash
|
|
69
|
+
# @api private
|
|
70
|
+
# @private
|
|
71
|
+
# Returns the hash to be changed
|
|
72
|
+
# @return [::Hash] hash to be changed
|
|
73
|
+
|
|
74
|
+
# @method base_key
|
|
75
|
+
# @api private
|
|
76
|
+
# @private
|
|
77
|
+
# Returns the base key of hash where subhash will be created
|
|
78
|
+
# @return [::String] base key of hash where subhash will be created
|
|
79
|
+
|
|
69
80
|
# @private
|
|
70
81
|
# Extract index of array from base_key
|
|
71
82
|
#
|
|
@@ -67,9 +67,14 @@ module Darthjee
|
|
|
67
67
|
|
|
68
68
|
private
|
|
69
69
|
|
|
70
|
-
# @private
|
|
71
70
|
attr_reader :separator
|
|
72
71
|
|
|
72
|
+
# @method separator
|
|
73
|
+
# @api private
|
|
74
|
+
# @private
|
|
75
|
+
# Returns the keys splitter
|
|
76
|
+
# @return [::String] keys splitter
|
|
77
|
+
|
|
73
78
|
# @private
|
|
74
79
|
# break the keys creating sub-hashes
|
|
75
80
|
#
|
|
@@ -7,6 +7,7 @@ module Darthjee
|
|
|
7
7
|
#
|
|
8
8
|
# @author Darthjee
|
|
9
9
|
class KeyChanger
|
|
10
|
+
# @param [::Hash] hash Hash to change keys of
|
|
10
11
|
def initialize(hash)
|
|
11
12
|
@hash = hash
|
|
12
13
|
end
|
|
@@ -153,6 +154,14 @@ module Darthjee
|
|
|
153
154
|
|
|
154
155
|
attr_reader :hash
|
|
155
156
|
|
|
157
|
+
# @method hash
|
|
158
|
+
# @api private
|
|
159
|
+
# @private
|
|
160
|
+
#
|
|
161
|
+
# Original hash to change keys of
|
|
162
|
+
#
|
|
163
|
+
# @return [::Hash] hash to change keys of
|
|
164
|
+
|
|
156
165
|
# @api private
|
|
157
166
|
# @private
|
|
158
167
|
#
|
|
@@ -44,6 +44,18 @@ module Darthjee
|
|
|
44
44
|
|
|
45
45
|
attr_reader :hash, :recursive
|
|
46
46
|
|
|
47
|
+
# @method hash
|
|
48
|
+
# @api private
|
|
49
|
+
# @private
|
|
50
|
+
# Returns the hash to be sorted
|
|
51
|
+
# @return [::Hash] hash to be sorted
|
|
52
|
+
|
|
53
|
+
# @method recursive
|
|
54
|
+
# @api private
|
|
55
|
+
# @private
|
|
56
|
+
# Returns the flag indicating to perform transformation recursively
|
|
57
|
+
# @return [::TrueClass,::FalseClass] flag indicating to perform transformation recursively
|
|
58
|
+
|
|
47
59
|
# @api private
|
|
48
60
|
# @private
|
|
49
61
|
#
|
|
@@ -15,8 +15,6 @@ module Darthjee
|
|
|
15
15
|
# @example (see Transformable#squash)
|
|
16
16
|
# @example (see #squash)
|
|
17
17
|
class Squasher
|
|
18
|
-
attr_reader :joiner
|
|
19
|
-
|
|
20
18
|
# @param joiner [::String] string used to join keys
|
|
21
19
|
def initialize(joiner = '.')
|
|
22
20
|
@joiner = joiner
|
|
@@ -79,6 +77,14 @@ module Darthjee
|
|
|
79
77
|
|
|
80
78
|
private
|
|
81
79
|
|
|
80
|
+
attr_reader :joiner
|
|
81
|
+
|
|
82
|
+
# @method joiner
|
|
83
|
+
# @api private
|
|
84
|
+
# @private
|
|
85
|
+
# Returns the string used to join keys
|
|
86
|
+
# @return [::String] string used to join keys
|
|
87
|
+
|
|
82
88
|
# @private
|
|
83
89
|
#
|
|
84
90
|
# Perform squashing on array
|