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

Add a load hook for ActiveModel::Model #48698

Merged
merged 1 commit into from Jul 10, 2023

Conversation

lewispb
Copy link
Contributor

@lewispb lewispb commented Jul 9, 2023

Motivation / Background

ActiveRecord::Base has a dedicated ActiveSupport load hook. This adds a hook for ActiveModel::Model, so that when ActiveModel is being used without ActiveRecord, it can still be modified.

Kredis would be able to use this hook here. Instead of:

config.after_initialize do
  ActiveModel::Model.include Kredis::Attributes if defined?(ActiveModel::Model)
end

we could write

ActiveSupport.on_load(:active_model) do
  include Kredis::Attributes
end

This change would help fix a reported issue at rails/kredis#60.

Detail

See the motivating issue at rails/kredis#60 and additional comment by @fxn here: rails/kredis#60 (comment)

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one change. Changes that are unrelated should be opened in separate PRs.
  • Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: [Fix #issue-number]
  • Tests are added or updated if you fix a bug or add a feature.
  • CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included.

ActiveRecord::Base has a dedicated ActiveSupport load hook. This adds an
additional hook for ActiveModel::Model, so that when ActiveModel is
being used without ActiveRecord, it can still be modified.
@guilleiguaran guilleiguaran merged commit 5515d1e into rails:main Jul 10, 2023
8 of 9 checks passed
@lewispb lewispb deleted the active-model-load-hook branch July 10, 2023 08:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants