Skip to content
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

Make initialiser for ARTPaginatedResult available #1984

Closed
wants to merge 1 commit into from

Conversation

umair-ably
Copy link
Contributor

@umair-ably umair-ably commented Oct 7, 2024

Make initialiser for ARTPaginatedResult available - allows mocking and subclassing in other SDKs e.g. Chat

Summary by CodeRabbit

  • New Features
    • Introduced a public initializer for the ARTPaginatedResult class, allowing users to create instances directly with the required parameters.
  • Bug Fixes
    • Prevented misuse of the ARTPaginatedResult class by enforcing a specific initialization pattern, ensuring proper instance creation.
  • Style
    • Minor formatting adjustments for improved code readability.

Copy link

coderabbitai bot commented Oct 7, 2024

Walkthrough

The changes in the ARTPaginatedResult.h and ARTPaginatedResult.m files involve modifications to the ARTPaginatedResult class interface. The initializer method has been updated from unavailable to publicly accessible, allowing direct instantiation of the class. Additionally, a new initializer in the implementation file enforces the use of a designated initializer for creating instances, preventing misuse. Minor formatting adjustments were also made, including comment alignment and whitespace removal.

Changes

File Change Summary
Source/include/Ably/ARTPaginatedResult.h Updated initializer from - (instancetype)init UNAVAILABLE_ATTRIBUTE; to - (instancetype)init;
Source/ARTPaginatedResult.m Added new initializer - (nonnull instancetype)init, enforcing use of designated initializer.

Poem

In the meadow where rabbits play,
A new path opens up today.
With a hop and a joyful cheer,
The ARTPaginatedResult draws near!
Now we can initialize with glee,
Hopping along, so wild and free! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot temporarily deployed to staging/pull/1984/features October 7, 2024 11:32 Inactive
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (1)
Source/include/Ably/ARTPaginatedResult.h (1)

Line range hint 1-53: Consider adding nullability annotation to the initializer.

The code looks good overall, with proper use of nullability annotations and documentation. For consistency with the rest of the interface, consider adding a nullability annotation to the newly public initializer.

Apply this minor change for consistency:

- - (instancetype)init;
+ - (nullable instancetype)init;

This change maintains consistency with the nullability annotations used throughout the rest of the interface.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 63e6f00 and 76bc268.

📒 Files selected for processing (1)
  • Source/include/Ably/ARTPaginatedResult.h (1 hunks)
🧰 Additional context used
🔇 Additional comments (1)
Source/include/Ably/ARTPaginatedResult.h (1)

Line range hint 1-53: Overall assessment: Changes align with PR objectives and maintain code quality.

The modification to make the initializer public achieves the goal of enabling mocking and subclassing of ARTPaginatedResult. The existing code structure, documentation, and use of nullability annotations demonstrate good coding practices. The suggested improvements are minor and focus on maintaining consistency within the interface.

Remember to update any relevant documentation or guides to reflect this new capability of directly initializing ARTPaginatedResult instances.

Source/include/Ably/ARTPaginatedResult.h Show resolved Hide resolved
@github-actions github-actions bot temporarily deployed to staging/pull/1984/jazzydoc October 7, 2024 11:36 Inactive
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
Source/ARTPaginatedResult.m (1)

140-143: Approved: Good addition to prevent misuse of the class.

The new initializer method effectively prevents the creation of ARTPaginatedResult instances without the required parameters. This aligns well with the PR objective and enforces proper usage of the class.

A minor suggestion for improvement:

Consider adding a more descriptive error message to guide developers on how to properly initialize the class. For example:

- [NSException raise:NSInternalInconsistencyException format:@"ARTPaginatedResult can't be initialized with init."];
+ [NSException raise:NSInternalInconsistencyException format:@"ARTPaginatedResult can't be initialized with init. Use initWithItems:rest:relFirst:relCurrent:relNext:responseProcessor:logger: instead."];

This change would provide clearer guidance to developers who might accidentally use the wrong initializer.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 76bc268 and 7148957.

📒 Files selected for processing (2)
  • Source/ARTPaginatedResult.m (1 hunks)
  • Source/include/Ably/ARTPaginatedResult.h (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • Source/include/Ably/ARTPaginatedResult.h
🧰 Additional context used
🔇 Additional comments (1)
Source/ARTPaginatedResult.m (1)

140-143: Verify impact and update documentation

The addition of this initializer enforces proper usage of the ARTPaginatedResult class, which is a positive change. However, to ensure a smooth transition:

  1. Verify that this change doesn't break existing code in other parts of the codebase or dependent SDKs.
  2. Update the class documentation to clearly state the correct way to initialize ARTPaginatedResult.

Run the following script to check for potential impacts:

Consider updating the class documentation in the header file (ARTPaginatedResult.h) to clearly state the correct initialization method. This will help prevent future misuse and provide clear guidance for developers.

Copy link
Collaborator

@lawrence-forooghian lawrence-forooghian left a comment

Choose a reason for hiding this comment

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

Make initialiser for ARTPaginatedResult available - allows mocking and subclassing in other SDKs e.g. Chat

I don't really understand what this PR does or why; please could you clarify?

  • What does the "available" in "Make initialiser for ARTPaginatedResult available" mean? You still get a runtime error if you try to call it.
  • If you wanted to subclass it in another SDK, what's the designated initializer that the subclass should call?

@@ -137,4 +137,9 @@ + (void)executePaginated:(ARTRestInternal *)rest withRequest:(NSMutableURLReques
}];
}

- (nonnull instancetype)init {
[NSException raise:NSInternalInconsistencyException format:@"ARTPaginatedResult can't be initialized with init."];
__builtin_unreachable();
Copy link
Collaborator

Choose a reason for hiding this comment

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

What does __builtin_unreachable do? I've never seen it before.

@umair-ably umair-ably closed this Oct 7, 2024
@umair-ably umair-ably deleted the allowARTPaginatedResultMocking branch October 7, 2024 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants