Skip to content

V4#461

Open
okuramasafumi wants to merge 3 commits intomainfrom
v4
Open

V4#461
okuramasafumi wants to merge 3 commits intomainfrom
v4

Conversation

@okuramasafumi
Copy link
Copy Markdown
Owner

@okuramasafumi okuramasafumi commented Aug 19, 2025

This new major version is backward incompatible.

Summary by CodeRabbit

  • Breaking Changes

    • Removed deprecated public API methods for inference control (enable_inference!, disable_inference!, inferring) and resource lookup (resource_with).
  • New Features

    • Added a public attributes hook method for custom attribute filtering.
  • Documentation

    • Updated attributes method documentation to reflect current usage patterns.

✏️ Tip: You can customize this high-level summary in your review settings.

@okuramasafumi okuramasafumi requested a review from Copilot August 19, 2025 10:25
@codecov
Copy link
Copy Markdown

codecov Bot commented Aug 19, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.35%. Comparing base (bab67e6) to head (7e83148).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #461      +/-   ##
==========================================
+ Coverage   97.73%   99.35%   +1.62%     
==========================================
  Files          14       14              
  Lines         661      623      -38     
  Branches      177      172       -5     
==========================================
- Hits          646      619      -27     
+ Misses         15        4      -11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

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

This PR introduces a major version 4 update that removes deprecated methods and refactors the attribute filtering mechanism. The changes focus on simplifying the API by removing legacy methods and replacing the attributes method override pattern with a more focused select method for filtering attributes.

Key changes include:

  • Removal of deprecated inference methods (enable_inference!, disable_inference!, inferring)
  • Removal of deprecated resource_with method in favor of resource_for
  • Replacement of attributes method override pattern with select method for attribute filtering
  • Removal of deprecated test cases for removed methods

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
lib/alba.rb Removes deprecated inference and resource methods
lib/alba/resource.rb Removes deprecated attributes method and updates attribute processing to use @_attributes directly
test/usecases/nested_array_and_hash_test.rb Updates from attributes override to select method implementation
test/usecases/inheritance_and_ignorance_test.rb Updates from attributes override to select method implementation
test/alba_test.rb Removes tests for deprecated methods

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.


def attributes
@_attributes.except(:config)
def select(key, *)
Copy link

Copilot AI Aug 19, 2025

Choose a reason for hiding this comment

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

The select method signature uses * to ignore additional parameters, but the method in inheritance_and_ignorance_test.rb explicitly names the second parameter as _value. Consider using a consistent signature across all implementations for better API clarity.

Suggested change
def select(key, *)
def select(key, _value)

Copilot uses AI. Check for mistakes.
Comment thread lib/alba/resource.rb
end

# Default implementation for selecting attributes
# Override this method to filter attributes based on key and value
Copy link

Copilot AI Aug 19, 2025

Choose a reason for hiding this comment

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

The select method lacks documentation explaining its purpose, parameters, and expected return value. This is especially important since it replaces the deprecated attributes method and users need to understand how to implement filtering logic.

Suggested change
# Override this method to filter attributes based on key and value
# Filters attributes during serialization.
#
# This method replaces the deprecated `attributes` method.
# Override this method to implement custom filtering logic for attributes.
#
# @param key [Symbol, String] the attribute key
# @param value [Object] the attribute value
# @param attribute [Alba::Attribute] the attribute object
# @return [Boolean] true to include the attribute, false to exclude it

Copilot uses AI. Check for mistakes.
BREAKING CHANGE!
This commit introduces one backward incompatibility where redefining
`converter` and `collection_converter` is now no-op.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Dec 30, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

This PR removes deprecated public APIs and internal code paths from Alba library, including inference control methods (enable_inference!, disable_inference!, inferring) and resource_with. It introduces a new public hook method attributes for attribute filtering and updates tests to use a new select-based filtering mechanism instead of the deprecated attributes approach.

Changes

Cohort / File(s) Summary
Deprecated public API removal
lib/alba.rb
Removed four deprecated public methods: enable_inference!(with:), disable_inference!, inferring, and resource_with(object, with: :inference, &block). These methods previously issued deprecation warnings.
Core resource refactoring
lib/alba/resource.rb
Introduced new public hook attributes returning @_attributes. Removed deprecated serialization paths: deprecated_serializable_hash, deprecated_serializable_hash_for_collection, and helper methods converter, collection_converter. Removed deprecation-wrapped method_added override. Updated serializable_hash flow to use the new attributes hook.
Deprecation test cleanup
test/alba_test.rb, test/resource_test.rb
Removed test cases for deprecated inference behavior (test_enable_inference_is_deprecated, test_disable_inference_is_deprecated, test_inferring_is_deprecated) and deprecated converter/attribute tests. Deleted DeprecatedConverterResource and DeprecatedConverterCollectionResource test helper classes.
Test resource migration
test/usecases/inheritance_and_ignorance_test.rb, test/usecases/nested_array_and_hash_test.rb
Migrated attribute filtering from overriding attributes method to implementing new select(key, ...) predicate method. Switches control flow from post-processing attributes to per-key inclusion checks during serialization.
Documentation update
README.md
Updated filtering attributes note to indicate attributes method is available as an option, removing language about deprecation and removal.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 Deprecated code hops away,
New hooks bloom in the light of day,
Select your attributes with care,
Alba's cleaner, fresh, and fair! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 41.67% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title check ❓ Inconclusive The title 'V4' is extremely vague and does not clearly describe the specific changes in the pull request. Replace 'V4' with a descriptive title that summarizes the main breaking changes, such as 'Remove deprecated APIs and simplify serialization for V4 major release' or 'Remove deprecated inference and converter methods'.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bab67e6 and 7e83148.

📒 Files selected for processing (7)
  • README.md
  • lib/alba.rb
  • lib/alba/resource.rb
  • test/alba_test.rb
  • test/resource_test.rb
  • test/usecases/inheritance_and_ignorance_test.rb
  • test/usecases/nested_array_and_hash_test.rb
💤 Files with no reviewable changes (3)
  • test/alba_test.rb
  • test/resource_test.rb
  • lib/alba.rb
🧰 Additional context used
📓 Path-based instructions (3)
test/**/*_test.rb

📄 CodeRabbit inference engine (AGENTS.md)

test/**/*_test.rb: Tests follow the Minitest layout in test/**/*_test.rb, with helpers inside test/support/ and scenario fixtures in test/usecases/
Minitest powers the suite and expects file names ending in _test.rb
Mirror runtime namespaces when adding tests and pull helpers from test/test_helper.rb
SimpleCov enforces branch coverage locally and in CI, so favour assertions that drive both truth paths

Files:

  • test/usecases/inheritance_and_ignorance_test.rb
  • test/usecases/nested_array_and_hash_test.rb
**/*.rb

📄 CodeRabbit inference engine (AGENTS.md)

**/*.rb: RuboCop targets Ruby 3.0 and governs import order, layout, and naming—accept its autofixes before committing
Predicate names such as select are pre-whitelisted; otherwise stick to idiomatic Ruby casing
Keep comments intentional and brief; prefer clarifying method names over inline notes

Files:

  • test/usecases/inheritance_and_ignorance_test.rb
  • test/usecases/nested_array_and_hash_test.rb
  • lib/alba/resource.rb
lib/**/*.rb

📄 CodeRabbit inference engine (AGENTS.md)

Core code lives under lib/, with lib/alba/ providing the serializer internals and alba.rb exposing the public API

Files:

  • lib/alba/resource.rb
🧠 Learnings (1)
📚 Learning: 2025-12-06T06:25:46.625Z
Learnt from: CR
Repo: okuramasafumi/alba PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-06T06:25:46.625Z
Learning: Applies to **/*.rb : Predicate names such as `select` are pre-whitelisted; otherwise stick to idiomatic Ruby casing

Applied to files:

  • test/usecases/inheritance_and_ignorance_test.rb
  • test/usecases/nested_array_and_hash_test.rb
🧬 Code graph analysis (2)
test/usecases/inheritance_and_ignorance_test.rb (3)
lib/alba/resource.rb (1)
  • select (216-218)
test/usecases/nested_array_and_hash_test.rb (1)
  • select (40-42)
test/usecases/no_association_test.rb (1)
  • select (154-156)
test/usecases/nested_array_and_hash_test.rb (3)
lib/alba/resource.rb (1)
  • select (216-218)
test/usecases/inheritance_and_ignorance_test.rb (2)
  • select (22-26)
  • select (23-25)
test/usecases/no_association_test.rb (1)
  • select (154-156)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: build (macos-latest, head, all)
  • GitHub Check: build (windows-latest, 3.1, without_active_support)
🔇 Additional comments (5)
test/usecases/inheritance_and_ignorance_test.rb (1)

22-26: LGTM!

The select implementation correctly uses the 3-parameter signature pattern (key, _value, *) which aligns with the default in lib/alba/resource.rb. The filtering logic properly restricts serialization to only the :name attribute.

lib/alba/resource.rb (3)

117-121: LGTM!

The new attributes hook method provides a clean public extension point for filtering attributes before serialization. This complements the per-attribute select hook nicely—attributes for bulk pre-filtering, select for conditional per-item filtering.


214-218: LGTM!

The default select implementation is correctly defined with the 3-parameter signature and includes brief documentation explaining its purpose. The implementation properly defaults to true to include all attributes unless overridden.


323-333: LGTM!

The method_added hook correctly captures the arity of overridden select methods, enabling the flexible 2-or-3 parameter invocation pattern in do_select. This design allows users to define select with either signature based on their needs.

README.md (1)

900-900: LGTM!

The documentation accurately reflects that both select and attributes instance methods can be used for filtering, aligning with the new attributes hook introduced in lib/alba/resource.rb.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@okuramasafumi okuramasafumi marked this pull request as ready for review December 31, 2025 14:57
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread lib/alba/resource.rb
Comment on lines 325 to 327
when :select
@_select_arity = instance_method(:select).arity
when :_setup # noop
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Exclude attributes overrides from resource-method list

With the README now allowing attributes overrides for filtering, method_added will add :attributes to _resource_methods. In that case, if a resource both overrides attributes and declares an attribute named :attributes (common on ActiveRecord models), _fetch_attribute_from_resource_first will route that key to the resource method and call attributes(obj), which raises ArgumentError because the override expects no arguments, breaking serialization. Previous versions avoided this by special-casing :attributes, so consider excluding it (or other filtering hooks) from _resource_methods to preserve the ability to serialize an object’s attributes value.

Useful? React with 👍 / 👎.

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.

2 participants