Skip to content

Add class methods from included concerns and fix ActiveRecord::Encryption for Rails 8.1 - #1089

Open
amatsuda wants to merge 7 commits into
ruby:mainfrom
amatsuda:rails-8.1-class-methods
Open

amatsuda wants to merge 7 commits into
ruby:mainfrom
amatsuda:rails-8.1-class-methods

Conversation

@amatsuda

Copy link
Copy Markdown
Member

Follow-up fixes for the Rails 8.1 signatures (#1084, #1086, #1087): class methods that classes get from the concerns they include, and ActiveRecord::Encryption's configuration API.

Class methods from concerns

ActiveSupport::Concern extends a class with the ClassMethods of the concerns it includes, directly or through other concerns. The RBS often didn't say so. The missing extends were computed with the RBS environment (concerns are modules that extend ActiveSupport::Concern; a class is skipped when its superclass lacks the same ones) and added right after the class header. The rest of each generated file is unchanged.

  • actionpack
    • ActionController::Base and API (hand-written, next to their includes): Redirecting, Renderers, Rescue, AbstractController::UrlFor, ActiveSupport::Callbacks, ActionView::Rendering and ViewPaths. Controllers had no use_renderers, allowed_redirect_hosts=, define_callbacks, or prepend_view_path
    • ActionController::TestCase (tests), ActionDispatch::IntegrationTest (register_encoder, with_routing), ActionDispatch::Request (parameter_parsers=), ActionDispatch::Callbacks
  • actionview: ActionView::Base (full_sanitizer, ...), ActionView::TestCase (tests, helper_method), Tags::Base
  • activemodel: ActiveModel::Type::Value (serialize_cast_value_compatible?)
  • activerecord: the connection adapters (quote_column_name, define_callbacks), Schema (define), PendingMigrationError and NoDatabaseError (action), Relation, column and type metadata classes
  • activesupport: CurrentAttributes and ExecutionWrapper (define_callbacks, set_callback)

ActiveRecord::Encryption

Encryption::Configurable and Contexts define their API in included do and class_methods do blocks, so the methods belong to ActiveRecord::Encryption, which includes both. rbs prototype skips class_methods blocks, and the accessors from the included blocks were declared as singleton methods of Configurable and Contexts. So ActiveRecord::Encryption.config, configure, context, with_encryption_context, without_encryption, protecting_encrypted_data, and on_encrypted_attribute_declared weren't available.

activerecord-generated.rbs is regenerated with:

  • The bodies of class_methods do ... end as the concern's ClassMethods (Configurable, Contexts, EncryptableRecord, ExtendedDeterministicQueries, ColumnMethods)
  • mattr_*/cattr_*/thread_mattr_accessor inside an included block going to ClassMethods, like class_attribute
  • ActiveRecord::Encryption extending the ClassMethods of the concerns it includes

The diff is limited to these. In the hand-written RBS, encrypted_attributes is removed from Base (it now comes from EncryptableRecord::ClassMethods), the context properties that Configurable delegates to the context (key_provider, encryptor, ...) are declared, and config and context return Encryption::Config and Encryption::Context.

Tests

Each commit adds tests that fail without it, and bin/test passes for each changed gem.

🤖 Generated with Claude Code

amatsuda and others added 7 commits October 13, 2026 20:53
…::Base and API include

The lists missed the ClassMethods of Redirecting, Renderers, Rescue, and
the concerns included through other concerns (AbstractController::UrlFor,
ActiveSupport::Callbacks, ActionView::Rendering and ViewPaths), so
controllers had no use_renderers, allowed_redirect_hosts=,
define_callbacks, or prepend_view_path.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…asses include

ActiveSupport::Concern extends a class with the ClassMethods of the
concerns it includes, directly or through other concerns. The generated
RBS didn't say so, so ActionController::TestCase had no tests,
ActionDispatch::IntegrationTest no register_encoder or with_routing,
ActionDispatch::Request no parameter_parsers=, and so on.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…asses include

ActiveSupport::Concern extends a class with the ClassMethods of the
concerns it includes, directly or through other concerns. The generated
RBS didn't say so. ActionView::Base had no full_sanitizer or sanitizer_vendor,
and ActionView::TestCase no tests or helper_method.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…lasses include

ActiveSupport::Concern extends a class with the ClassMethods of the
concerns it includes, directly or through other concerns. The generated
RBS didn't say so. ActiveModel::Type::Value had no serialize_cast_value_compatible?.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…classes include

ActiveSupport::Concern extends a class with the ClassMethods of the
concerns it includes, directly or through other concerns. The generated
RBS didn't say so. For example, the connection adapters had no
quote_column_name or define_callbacks, ActiveRecord::Schema no define,
and PendingMigrationError no action.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
… classes include

ActiveSupport::Concern extends a class with the ClassMethods of the
concerns it includes, directly or through other concerns. The generated
RBS didn't say so. CurrentAttributes and ExecutionWrapper had no
define_callbacks or set_callback.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…t methods

Configurable and Contexts define them in their included block and
class_methods block, so they're methods of ActiveRecord::Encryption,
which includes both. rbs prototype skips class_methods blocks, and the
accessors from the included blocks were declared as singleton methods
of Configurable and Contexts, so ActiveRecord::Encryption.config,
configure, context, without_encryption, protecting_encrypted_data, and
with_encryption_context weren't available.

Regenerate with the bodies of `class_methods do ... end` as the
concern's ClassMethods (also for EncryptableRecord, ColumnMethods, and
ExtendedDeterministicQueries), with mattr/cattr accessors in an included
block going to ClassMethods like class_attribute, and with
ActiveRecord::Encryption extending the ClassMethods of the concerns it
includes. EncryptableRecord's class_attribute now goes to its
ClassMethods, so remove encrypted_attributes from the hand-written
Base. Declare the context properties that Configurable delegates to the
context, and type config and context.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

@amatsuda Thanks for your contribution!

Please follow the instructions below for each change.
See also: https://github.com/ruby/gem_rbs_collection/blob/main/docs/CONTRIBUTING.md

Available commands

You can use the following commands by commenting on this PR.

  • /merge: Merge this PR if CI passes

actionpack

You changed RBS files for an existing gem.
You need to get approval from the reviewers of this gem.

@ksss, @tk0miya, please review this pull request.
If this change is acceptable, please make a review comment including APPROVE from here.
Screen Shot 2024-03-19 at 14 13 36

After that, the PR author or the reviewers can merge this PR.
Just comment /merge to merge this PR.


actionview

You changed RBS files for an existing gem.
You need to get approval from the reviewers of this gem.

@ksss, @ydah, @tk0miya, please review this pull request.
If this change is acceptable, please make a review comment including APPROVE from here.
Screen Shot 2024-03-19 at 14 13 36

After that, the PR author or the reviewers can merge this PR.
Just comment /merge to merge this PR.


activemodel

You changed RBS files for an existing gem.
You need to get approval from the reviewers of this gem.

@hibariya, @ksss, @tk0miya, please review this pull request.
If this change is acceptable, please make a review comment including APPROVE from here.
Screen Shot 2024-03-19 at 14 13 36

After that, the PR author or the reviewers can merge this PR.
Just comment /merge to merge this PR.


activerecord

You changed RBS files for an existing gem.
You need to get approval from the reviewers of this gem.

@hibariya, @ksss, @Little-Rubyist, @tk0miya, please review this pull request.
If this change is acceptable, please make a review comment including APPROVE from here.
Screen Shot 2024-03-19 at 14 13 36

After that, the PR author or the reviewers can merge this PR.
Just comment /merge to merge this PR.


activesupport

You changed RBS files for an existing gem.
You need to get approval from the reviewers of this gem.

@hibariya, @ksss, @ydah, @tk0miya, please review this pull request.
If this change is acceptable, please make a review comment including APPROVE from here.
Screen Shot 2024-03-19 at 14 13 36

After that, the PR author or the reviewers can merge this PR.
Just comment /merge to merge this PR.

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.

1 participant