Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Railsの型ファイル自動生成における課題と解決

ksss
October 28, 2023

 Railsの型ファイル自動生成における課題と解決

Kaigi on Rails 2023 at 浅草橋ヒューリックホール&カンファレンス

ksss

October 28, 2023
Tweet

More Decks by ksss

Other Decks in Programming

Transcript

  1. ˜.*9* 13 orthoses-rails $ bundle add orthoses-rails —require false $

    bin/rails generate orthoses:rails:install $ bin/rails orthoses:rails $ bundle exec rbs collection init $ bundle exec rbs collection install
  2. ˜.*9* 25 ՝୊ ՝୊: Ξϓ Ϧέʔγϣ ϯίʔυͷ ܕ͕͍ͭͯ ͍ͳ͍ ղܾ:

    rbs prototype rb eval, define_method ActiveSupport::Concern Array, Hash, Enumerable delegate
  3. ˜.*9* 27 ղܾ rbs prototype runtime ՝୊: Ξϓ Ϧέʔγϣ ϯίʔυͷ

    ܕ͕͍ͭͯ ͍ͳ͍ ղܾ: rbs prototype rb ՝୊: ͍Ζ ͍ΖඇରԠ
  4. ˜.*9* 29 ՝୊ ՝୊: Ξϓ Ϧέʔγϣ ϯίʔυͷ ܕ͕͍ͭͯ ͍ͳ͍ ղܾ:

    rbs prototype rb ՝୊: ͍Ζ ͍ΖඇରԠ ղܾ: rbs prototype runtime autoloadඇରԠ ஗͍
  5. ˜.*9* 30 ղܾ ՝୊: Ξϓ Ϧέʔγϣ ϯίʔυͷ ܕ͕͍ͭͯ ͍ͳ͍ ղܾ:

    rbs prototype rb ՝୊: ͍Ζ ͍ΖඇରԠ ղܾ: rbs prototype runtime Pull Request ՝୊: ͍Ζ ͍Ζ໰୊͕
  6. ˜.*9* 32 ՝୊ ՝୊: Ξϓ Ϧέʔγϣ ϯίʔυͷ ܕ͕͍ͭͯ ͍ͳ͍ ղܾ:

    rbs prototype rb ՝୊: ͍Ζ ͍ΖඇରԠ ղܾ: rbs prototype runtime ActiveRecord Plugins ΋ͬͱػೳΛʂ untyped Gemͷܕ
  7. https://speakerdeck.com/ksss/rbs-generation-framework-using-rack-architecture Orthoses::Builder.new do use Orthoses::CreateFileByName use Orthoses::Mid, option: true use

    Orthoses::Tap do |store| store["Foo"] << "def foo: () -> void" end use Orthoses::Mixin run -> { require '...' } end
  8. ˜.*9* rbs prototype rb rbs prototype runtime orthoses eval ActiveSupport::

    Concern Generics delegate autoload Speed Extensibility
  9. ˜.*9* 54 orthoses-yard # @param [String] str # @return [Integer]

    def str_to_i(str) str.to_i end def str_to_i: (String str) -> Integer .rb .rbs
  10. ˜.*9* 59 YARD͸ҙ֎ͱ೉͍͠ # @param [String|Symbol] # @param [Hash<Symbol, String>]

    h # @param [String] s def foo(str) SyntaxError Hash[Symbol | String] def foo: (untyped str) -> untyped
  11. ˜.*9* 69 ·ͱΊ orthoses use Orthoses::LoadRBS use Orthoses::YARD use Orthoses::RBSPrototypeRuntime

    use Orthoses::Rails Rails×ܕͷੈք΁ͷఏҊ use Your::Middleware