Skip to content

Extract shared Displayable concern from Mod and Tool models#72

Merged
dyoung522 merged 2 commits intomainfrom
enhance/dry-up-models
Feb 10, 2026
Merged

Extract shared Displayable concern from Mod and Tool models#72
dyoung522 merged 2 commits intomainfrom
enhance/dry-up-models

Conversation

@dyoung522
Copy link
Contributor

Extracts duplicated methods from Mod and Tool into a new Displayable concern:

  • readme / details — memoized README fetching with description fallback
  • author_slug — parameterized author name
  • updated_string / version_string — display formatting
  • fetch_readme — HTTP fetch with comprehensive error handling

Before: ~50 lines duplicated across both models
After: Single source of truth in app/models/concerns/displayable.rb

230 specs passing, RuboCop clean.

Closes #63

Moves duplicated methods into a shared concern:
- readme / details (memoized README fetching with fallback)
- author_slug (parameterized author name)
- updated_string / version_string (display formatting)
- fetch_readme (HTTP fetch with error handling)

Reduces ~50 lines of duplication between the two models.

Closes #63
Copilot AI review requested due to automatic review settings February 10, 2026 01:20
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Extracts duplicated presentation- and README-fetching behavior from Mod and Tool into a shared Displayable concern to reduce duplication and keep formatting/fetch logic consistent across both models.

Changes:

  • Added Displayable concern encapsulating readme/details, author_slug, updated_string, version_string, and fetch_readme.
  • Updated Mod and Tool to include Displayable and removed their duplicated implementations.
  • Fixed spelling in Mod comments (“Determins” → “Determines”).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
app/models/tool.rb Replaces duplicated display/README methods with include Displayable.
app/models/mod.rb Replaces duplicated display/README methods with include Displayable (plus comment typo fixes).
app/models/concerns/displayable.rb Introduces shared concern for README fetching and display helpers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


def fetch_readme
# We strip out the first # line of the README, as it's usually a title
Net::HTTP.get(raw_uri(readme_url)).gsub(/^#\s+.*$/, "").strip
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fetch_readme, the regex gsub(/^#\s+.*$/, "") will remove every Markdown heading line in the README (because ^/$ match line boundaries), not just the first title line as the comment says. If the goal is to strip only the leading H1/title, consider using sub anchored to the start of the string (e.g., \A#...) or otherwise limiting the replacement to the first match so subsequent headings are preserved.

Suggested change
Net::HTTP.get(raw_uri(readme_url)).gsub(/^#\s+.*$/, "").strip
Net::HTTP.get(raw_uri(readme_url)).sub(/\A#\s+.*\n?/, "").strip

Copilot uses AI. Check for mistakes.
The original gsub(/^#\s+.*$/) removed ALL markdown heading lines.
Changed to sub(/\A#\s+.*\n?/) to strip only the first H1 at the
start of the document, preserving other headings in the README.

Addresses CoPilot review feedback.
@dyoung522 dyoung522 merged commit caf8d35 into main Feb 10, 2026
2 checks passed
@dyoung522 dyoung522 deleted the enhance/dry-up-models branch February 10, 2026 01:47
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.

DRY up duplicated code between Mod and Tool models

2 participants