Skip to content

feat: modernize ActiveModel integration with backward compatibility#45

Merged
seuros merged 1 commit intomasterfrom
compta
Jun 29, 2025
Merged

feat: modernize ActiveModel integration with backward compatibility#45
seuros merged 1 commit intomasterfrom
compta

Conversation

@seuros
Copy link
Copy Markdown
Member

@seuros seuros commented Jun 29, 2025

Support legacy syntax.

@seuros seuros requested a review from Copilot June 29, 2025 17:07
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 modernizes the ActiveModel integration to support both legacy positional hash initializers and new keyword argument syntax while preserving backward compatibility.

  • Adds compatibility tests for positional hashes, keyword args, empty initialization, and attribute aliases
  • Updates the generated initialize helper to accept params = nil, **kwargs and dispatch correctly
  • Ensures positional arguments take precedence when both styles are provided

Reviewed Changes

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

File Description
test/machine_initialization_compatibility_test.rb New tests covering legacy and keyword initialization modes, empty init, attribute aliases, and precedence rules
lib/state_machines/integrations/active_model.rb Refactored define_state_initializer to handle positional and keyword args and forward them to super
Comments suppressed due to low confidence (1)

lib/state_machines/integrations/active_model.rb:356

  • [nitpick] The parameter name kwargs is less common in Ruby; consider renaming it to keyword_params for clarity and consistency with Ruby naming conventions.
          def initialize(params = nil, **kwargs)

params.transform_keys! do |key|
def initialize(params = nil, **kwargs)
# Support both positional hash and keyword arguments
attrs = params || kwargs
Copy link

Copilot AI Jun 29, 2025

Choose a reason for hiding this comment

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

Using params || kwargs will treat an empty params hash as present and ignore keyword args even when they have values. Consider using attrs = params.nil? ? kwargs : params to explicitly check for an absent positional argument.

Suggested change
attrs = params || kwargs
attrs = params.nil? ? kwargs : params

Copilot uses AI. Check for mistakes.
avoid breaking reality for apps that don't update the syntax
@seuros seuros merged commit a0a6c5f into master Jun 29, 2025
14 checks passed
@seuros seuros deleted the compta branch June 29, 2025 17:23
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