Skip to content

Replace case statement in Claude Message.from_hash with dynamic class resolution#913

Open
juniper-shopify wants to merge 1 commit into
mainfrom
juni/Generate_claude_message_type_class_name_automatically
Open

Replace case statement in Claude Message.from_hash with dynamic class resolution#913
juniper-shopify wants to merge 1 commit into
mainfrom
juni/Generate_claude_message_type_class_name_automatically

Conversation

@juniper-shopify
Copy link
Copy Markdown
Contributor

@juniper-shopify juniper-shopify commented Jun 2, 2026

Closes: #911

Copy link
Copy Markdown
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@juniper-shopify juniper-shopify changed the title Generate claude message type class name automatically Replace case statement in Claude Message.from_hash with dynamic class resolution Jun 2, 2026
@juniper-shopify juniper-shopify marked this pull request as ready for review June 2, 2026 21:00

private

#: (Symbol?) -> Class
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think changing this to #: (Symbol?) -> singleton(Message) would be more precise and fix the failing CI check.

def resolve_message_class(type)
return Messages::UnknownMessage if type.nil?

class_name = "#{type}_message".camelize
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Are we ever concerned by the fact that .camelize could give us a result that generates a nameError when evaluated in Messages.const_defined?(class_name, false) (such as if the type has a hyphen)?

We can expect that it shouldn't really happen but it might be worth it to add a rescue nameErrorthat also returns Messages::UnknownMessagefor extra robustness.

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.

Replace case statement in Claude Message.from_hash with dynamic class resolution

2 participants