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

RBS generation framework using Rack architecture

ksss
September 09, 2022

RBS generation framework using Rack architecture

The presentation slides from RubyKaigi2022.

See also https://rubykaigi.org/2022/presentations/_ksss_.html

ksss

September 09, 2022
Tweet

More Decks by ksss

Other Decks in Programming

Transcript

  1. RBS generation framework using Rack architecture

  2. ksss Yuki Kurihara READYFOR, inc. From KOKA(ߕլ) in SHIGA

  3. Logic model

  4. Impact Happy Hacking

  5. Outcome Type Everywhere H H

  6. Outputs in long Auto Generation Type File T E

  7. Outputs In short Implementation Marketing A G T

  8. Implementation

  9. Issues Needs a lot of Type Needs accuracy Needs expandability

    Needs flexibility
  10. TracePoint TracePoint.new(:call) do |tp| args = tp.parameters.to_h do |op, name|

    b = tp.binding [name, b.local_variable_get(name).dup] end p [tp.self, args] end.enable(target: target) do require '...' end
  11. Needs a New 
 Model Load Before After Feature

  12. Rack Architecture

  13. use Middleware1 use Middleware2 use Middleware3 run App.new Rack Architecture

  14. use Middleware1 use Middleware2 use Middleware3 run -> { require

    'library' } Use case for Library
  15. require 'library' use Middleware1 use Middleware2 use Middleware3 run ->

    { Rails.application.eager_load! } Use case for Application
  16. Sponsored by

  17. Sponsored by

  18. New Product

  19. Orthoses IUUQTHJUIVCDPNLTTTPSUIPTFT IUUQTFOXJLJQFEJBPSHXJLJ0SUIPUJDT

  20. Rack Orthoses class Middleware def initialize(app) @app = app end

    def call(env) @app.call(env) end end class Middleware def initialize(loader) @loader = loader end def call @loader.call end end
  21. Store store = @loader.call pp store #=> { "Foo" =>

    #<Content>, "Bar::Baz" => #<Content> }
  22. Content store = @loader.call store["Foo"] << "def foo: () ->

    int" store["Foo"] << "alias bar foo" store["Foo"] << "include Baz"
  23. CallTracer foo = CallTracer.new store = foo.trace(Foo.method(:foo)) do @loader.call end

    foo.captures.each do |capture| capture.method.receiver capture.argument[:name] end
  24. CallTracer::Lazy foo = CallTracer::Lazy.new store = foo.trace('Foo#foo')) do @loader.call end

    foo.captures.each do |capture| capture.method.receiver capture.argument[:name] end
  25. Builder example 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
  26. Middleware Example module Orthoses class Mid def initialize(loader, option: false)

    @loader = loader @option = option end def call foo = Orthoses::CallTracer::Lazy.new store = foo.trace('Foo#foo') do @loader.call end foo.captures.each do |capture| mod = capture.method.receiver name = Utils.module_name(mod) or next store[name] << "def bar: () -> void" end store end
  27. Nest to Line VTF VTF VTF

  28. Middlewares •include, extend and prepend •attr_accessor, attr_writer and attr_reader •ObjectSpace

    •Constants •Tap and PP •RBS prototype
  29. Middlewares •Load RBS •Filter •Create file by name •Autoload •DelegateClass

  30. Orthoses-rails for Application •has_many, has_one and belongs_to •enum •delegated_type •scope

    •has_secure_password IUUQTHJUIVCDPNLTTTPSUIPTFTSBJMT
  31. Orthoses-rails for gems •TimeWithZone •railties •delegate •class_attribute, mattr_accessor IUUQTHJUIVCDPNLTTTPSUIPTFTSBJMT

  32. You can create extension gems •orthoses-yard •orthoses-typeprof •orthoses-rolify

  33. Feature tasks •gem_rbs_collection •Support Rails Application •Usability •Newcomers

  34. Special Thanks QPDLF LP

  35. Happy Hacking