$30 off During Our Annual Pro Sale. View Details »

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

    View Slide

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

    View Slide

  3. Logic model

    View Slide

  4. Impact
    Happy
    Hacking

    View Slide

  5. Outcome Type
    Everywhere
    H
    H

    View Slide

  6. Outputs


    in long Auto
    Generation
    Type File
    T
    E

    View Slide

  7. Outputs


    In short
    Implementation
    Marketing
    A
    G
    T

    View Slide

  8. Implementation

    View Slide

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

    View Slide

  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

    View Slide

  11. Needs a


    New

    Model
    Load
    Before
    After
    Feature

    View Slide

  12. Rack
    Architecture

    View Slide

  13. use Middleware1


    use Middleware2


    use Middleware3


    run App.new
    Rack Architecture

    View Slide

  14. use Middleware1


    use Middleware2


    use Middleware3


    run -> {


    require 'library'


    }
    Use case for Library

    View Slide

  15. require 'library'


    use Middleware1


    use Middleware2


    use Middleware3


    run -> {


    Rails.application.eager_load!


    }
    Use case for Application

    View Slide

  16. Sponsored by

    View Slide

  17. Sponsored by

    View Slide

  18. New Product

    View Slide

  19. Orthoses
    IUUQTHJUIVCDPNLTTTPSUIPTFT
    IUUQTFOXJLJQFEJBPSHXJLJ0SUIPUJDT

    View Slide

  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

    View Slide

  21. Store
    store = @loader.call


    pp store


    #=> {


    "Foo" => #,


    "Bar::Baz" => #


    }

    View Slide

  22. Content
    store = @loader.call


    store["Foo"] << "def foo: () -> int"


    store["Foo"] << "alias bar foo"


    store["Foo"] << "include Baz"

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  27. Nest to Line
    VTF
    VTF
    VTF

    View Slide

  28. Middlewares
    •include, extend and prepend


    •attr_accessor, attr_writer and attr_reader


    •ObjectSpace


    •Constants


    •Tap and PP


    •RBS prototype

    View Slide

  29. Middlewares
    •Load RBS


    •Filter


    •Create file by name


    •Autoload


    •DelegateClass

    View Slide

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


    •enum


    •delegated_type


    •scope


    •has_secure_password
    IUUQTHJUIVCDPNLTTTPSUIPTFTSBJMT

    View Slide

  31. Orthoses-rails for gems
    •TimeWithZone


    •railties


    •delegate


    •class_attribute, mattr_accessor
    IUUQTHJUIVCDPNLTTTPSUIPTFTSBJMT

    View Slide

  32. You can create extension gems
    •orthoses-yard


    •orthoses-typeprof


    •orthoses-rolify

    View Slide

  33. Feature tasks
    •gem_rbs_collection


    •Support Rails Application


    •Usability


    •Newcomers

    View Slide

  34. Special Thanks
    QPDLF LP

    View Slide

  35. Happy Hacking

    View Slide