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

RubyのOSSコードリーディング / ruby-oss-code-reading

Osamtimizer
November 30, 2019

RubyのOSSコードリーディング / ruby-oss-code-reading

Osamtimizer

November 30, 2019
Tweet

More Decks by Osamtimizer

Other Decks in Programming

Transcript

  1. SBDLVQ def start server.run wrapped_app, options, &blk end def server

    @_server ||= Rack::Handler.get(options[:server]) @_server end lib/rack/server.rb
  2. SBDLVQ # *Handlers* connect web servers with Rack. # #

    Rack includes Handlers for Thin, WEBrick, FastCGI, CGI, SCGI # and LiteSpeed. # # Handlers usually are activated by calling <tt>MyHandler.run(myapp)</tt>. # A second optional hash can be passed to include server-specific # configuration. module Handler def self.get(server) lib/rack/handler.rb
  3. SBDLVQ # *Handlers* connect web servers with Rack. # #

    Rack includes Handlers for Thin, WEBrick, FastCGI, CGI, SCGI # and LiteSpeed. # # Handlers usually are activated by calling <tt>MyHandler.run(myapp)</tt>. # A second optional hash can be passed to include server-specific # configuration. module Handler def self.get(server) lib/rack/handler.rb
  4. SBDLVQ def self.get(server) … if klass = @handlers[server] klass.split("::").inject(Object) {

    |o, x| o.const_get(x) } lib/rack/handler.rb: L21-22 wͲ͏΍ΒɺHandler.getͰ͸͜ͷߦͷ݁Ռ͕ฦ͍ͬͯΔΒ͍͠
  5. CJOEJOHJSC irb(Rack::Handler):001:0> server => "puma" irb(Rack::Handler):002:0> @handlers => {“cgi”=>”Rack::Handler::CGI”, ...

    , ”puma”=>"Rack::Handler::Puma"} irb(Rack::Handler):003:0> @handlers[server] => "Rack::Handler::Puma" irb(Rack::Handler):004:0> klass.split("::") => ["Rack", "Handler", "Puma"]
  6. CJOEJOHJSC irb(Rack::Handler):001:0> result = ["Rack", "Handler", “Puma"].inject(Object) { |o, x|

    o.const_get(x) } => Rack::Handler::Puma irb(Rack::Handler):002:0> result.class => Module
  7. if klass = @handlers[server] klass.split("::").inject(Object) { |o, x| o.const_get(x) }

    αʔό໊ʢserverʣΛจࣈྻͰड͚औΓɺ Ұக͢Δ3BDL)BOEMFSͷϞδϡʔϧΦϒδΣΫτΛฦ͢ lib/rack/handler.rb SBDLVQ