Skip to content

Fix Rubocop Metrics/ClassLength offense #825

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 6, 2025
Merged

Conversation

jcouball
Copy link
Member

@jcouball jcouball commented Jul 6, 2025

Changes include:

(see the individual commit messages for more information)

  • Excluding the test suite from this requirement until the test suite is
    rewritten in RSpec.
  • Refactoring Git::Status

jcouball added 3 commits July 6, 2025 13:04
Exclude tests from the Metrics/ClassLength Rubocop offfense
since the plan is to rewrite the test suite in RSpec. At that time
many of the Rubocop exclusions will be removed.
This refactoring streamlines the Git::Status class by decomposing
its responsibilities, resulting in cleaner, more focused components:

* `StatusFile`: The inner data responsibilities was moved to its
  own class.
* `StatusFileFactory`: A new private factory was created to
  encapsulate all the logic for executing git commands and parsing
  their output into StatusFile objects.

I think the result is more readable and maintainable code.
The Git::Log class had grown to over 150 lines, making it difficult
to read and maintain. This refactoring simplifies the internal
implementation to improve its structure and reduce its size to under
100 lines, without altering the public API.

The primary motivations were to enhance readability and make the
class easier to extend in the future.

The key changes include:

- Consolidated all query parameters from individual instance
  variables into a single `@options` hash to simplify state
  management.
- Replaced repetitive builder methods with a concise `set_option`
  private helper, reducing code duplication.
- Centralized the command execution logic into a single
  `run_log_if_dirty` method to ensure consistent behavior.
- Simplified the deprecated Enumerable methods by using a helper
  for warnings and safe navigation (`&.`) for cleaner error handling.
- Modernized the nested `Git::Log::Result` class to use
  `Data.define`, leveraging Ruby 3.2+ features to create a more
  concise and immutable result object.
@jcouball jcouball force-pushed the metrics_class_length branch from 4687806 to b00ca52 Compare July 6, 2025 21:11
@jcouball jcouball merged commit 1aae57a into main Jul 6, 2025
7 checks passed
@jcouball jcouball deleted the metrics_class_length branch July 6, 2025 23:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant