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. 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
  2. require 'library' use Middleware1 use Middleware2 use Middleware3 run ->

    { Rails.application.eager_load! } Use case for Application
  3. 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
  4. Store store = @loader.call pp store #=> { "Foo" =>

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

    int" store["Foo"] << "alias bar foo" store["Foo"] << "include Baz"
  6. 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
  7. 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
  8. 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
  9. 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