Skip to content

Add types for actiontext v8.1 - #1094

Open
amatsuda wants to merge 23 commits into
ruby:mainfrom
amatsuda:actiontext-8.1
Open

amatsuda wants to merge 23 commits into
ruby:mainfrom
amatsuda:actiontext-8.1

Conversation

@amatsuda

Copy link
Copy Markdown
Member

Adds signatures for actiontext 8.1, based on 8.1.4.

This PR is stacked on #1093 (activestorage 8.1), which is stacked on #1090 (activejob 8.1), because actiontext 8.1 needs their signatures. Until they are merged, their commits show up here too. The commits for this PR are the ones starting with actiontext:.

The latest version in this repository was actiontext 7.2, which had only hand-written signatures for has_rich_text. This PR adds signatures generated from the 8.1.4 source and carries over the hand-written ones.

How it is made

actiontext-generated.rbs comes from rbs prototype rb run on lib and app, then post-processed the same way as the other Rails 8.1 gems:

  • Drop members that core, dependencies, or the hand-written RBS already define
  • Fill missing type arguments of generic classes with untyped
  • Drop mixins and superclasses that can't be resolved
  • Add accessors defined with class_attribute, mattr_accessor, and cattr_accessor, and methods defined with delegate
  • Generate the methods defined inside class_methods do ... end as the concern's ClassMethods, which rbs prototype skips
  • Make the generated classes extend the ClassMethods of the concerns they include, directly or through other concerns, as ActiveSupport::Concern does. For example, ActionText::Content gets render, load, and dump

The generators in lib/generators and lib/rails are left out, since their superclasses come from railties, which actiontext doesn't depend on.

Changes to the hand-written RBS

  • has_rich_text takes store_if_blank:, added in 8.0

Methods the generator doesn't see

The columns and associations of ActionText::RichText (name, body, record, embeds, ...), since the model is in the gem, so apps' generated model signatures don't have them.

Return types

RichText#to_s, to_plain_text, and to_trix_html, and Content's links, attachments, and HTML and plain text conversions.

Optional blocks

All required blocks were checked against the source, and 4 were made optional: rich_textarea (form helper and form builder), which uses the block for the value only when given, and ActionText::Content.render.

Tests

Each commit that changes types adds tests that fail without it. bin/test gems/actiontext/8.1 and RuboCop's strict cops pass on every commit from the generation commit onward.

🤖 Generated with Claude Code

amatsuda and others added 22 commits October 13, 2026 18:59
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Generated with `rbs prototype rb` from the activejob 8.1.4 source and
post-processed the same way as the other Rails 8.1 gems: drop members
already defined elsewhere, fill missing type arguments, add accessors
defined with class_attribute, mattr_accessor, and cattr_accessor, add
methods defined with delegate, and carry over typed signatures from 6.0
where the method still has the same parameters.

The job generator in lib/rails is left out, as its superclass comes from
railties, which activejob doesn't depend on.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Rails no longer has QueAdapter or SuckerPunchAdapter, so nothing refers
to Que::Job or SuckerPunch::Job.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Logging defines them on the job class with cattr_accessor and
class_attribute in its included block, which rbs prototype doesn't see.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
job_id, arguments, executions, queue_name, priority, and the other job
attributes, enqueue, and perform_later, which returns the job or false
when it couldn't be enqueued.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
rbs prototype marks a block as required unless the method checks it.
These forward the block or don't use it: the callbacks with method names
(before_perform :foo), assert_no_enqueued_jobs and
assert_no_performed_jobs without a block, and a few internal methods.

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

ActiveJob::Callbacks and ActiveJob::Exceptions include
ActiveSupport::Callbacks and ActiveSupport::Rescuable, so job classes
have rescue_from and set_callback.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
7.0 had only hand-written signatures. 8.1 adds signatures generated with
`rbs prototype rb` from the activestorage 8.1.4 lib and app sources and
post-processed the same way as the other Rails 8.1 gems: drop members
already defined elsewhere, fill missing type arguments, and add
accessors defined with class_attribute, mattr_accessor, and
cattr_accessor and methods defined with delegate. Methods defined
inside `class_methods do ... end` are generated as the concern's
ClassMethods.

ActiveStorage::Blobs and ActiveStorage::Representations, which Zeitwerk
defines for the controllers in app, are declared as modules.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
They were deprecated in 6.1 and removed in 7.0.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
- has_one_attached and has_many_attached take a block to declare named
  variants, which yields the attachment reflection
- The reflections inherit HasAttachedReflection, which has variant and
  named_variants
- Blob#signed_id takes purpose:, expires_in:, and expires_at:, and
  returns a String

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
They're defined by the active_storage_blobs and
active_storage_attachments tables and belongs_to/has_many, which rbs
prototype doesn't see, and the models are in the gem, so apps' generated
model signatures don't have them.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
key, filename, url, the content type predicates, and the direct upload
URL and headers of Blob, and the parts of Filename.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
rbs prototype marks a block as required unless the method checks it.
Variant#download and Preview#download pass the block to the service,
and return the content when called without one, like Blob#download. The
instrument methods pass it to ActiveSupport::Notifications.instrument.

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

The generated classes now extend the ClassMethods of the concerns they
include, directly or through other concerns, as ActiveSupport::Concern
does. FixtureSet gets generate_unique_secure_token, for example.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
7.2 had only hand-written signatures. 8.1 adds signatures generated with
`rbs prototype rb` from the actiontext 8.1.4 lib and app sources and
post-processed the same way as the other Rails 8.1 gems: drop members
already defined elsewhere, fill missing type arguments, and add
accessors defined with class_attribute, mattr_accessor, and
cattr_accessor and methods defined with delegate. Methods defined
inside `class_methods do ... end` are generated as the concern's
ClassMethods.

The generators in lib/generators and lib/rails are left out, as their
superclasses come from railties, which actiontext doesn't depend on.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
It was added in 8.0.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
rbs prototype marks a block as required unless the method checks it.
rich_textarea passes the block to rich_textarea_tag, which uses it for
the value only when given, and ActionText::Content.render passes it to
render_to_string.

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

The generated classes now extend the ClassMethods of the concerns they
include, directly or through other concerns, as ActiveSupport::Concern
does. ActionText::Content gets render, load, and dump, and
ActionText::Attachment gets the minification and Trix conversion
methods, for example.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
They're defined by the action_text_rich_texts table, belongs_to, and
has_many_attached, which rbs prototype doesn't see, and the model is in
the gem, so apps' generated model signatures don't have them.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
to_s, to_plain_text, and to_trix_html of RichText, and the links,
attachments, and HTML and plain text conversions of Content.

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

actiontext

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

@tk0miya, @ksss, 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.


activejob

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.


activestorage

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.

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