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

ActionDispatch ってなんだろう?

ActionDispatch ってなんだろう?

広島岡山Ruby交流会 01 での発表資料。 http://hirosimaokayamarb.doorkeeper.jp/events/8993

Railsのソースコードリーディングをしているので、その成果を発表です。
http://blog.eiel.info/blog/2014/03/30/action-dispatch/

Tomohiko Himura

March 29, 2014
Tweet

More Decks by Tomohiko Himura

Other Decks in Programming

Transcript

  1. Ruby on Rails • Railties • ActionPack • ActionDispatch •

    ActionController • AbstractController • ActiveModel • ActiveRecord • ActionView • ActiveSupport • ActionMailer
  2. .7$

  3. ࣮ࡍʹݟͯΈΔ $ rails -v Rails 4.1.0.rc2 $ rails new hoge

    $ cd hoge # gem ‘pry-rails’ ͯ͠Δ͜ͱʹ͠ͱ͖·͢ $ rails c
  4. 3BJMT"QQMJDBUJPO > Rails.application.class => Hoge::Application > Rails.application.class.ancestors => [Hoge::Application, Rails::Application,

    Rails::Engine, Rails::Railtie, Rails::Initializable, Object, ActiveSupport::Dependencies::Loadable, PP::ObjectMixin, JSON::Ext::Generator::GeneratorMethods::Object, Kernel, BasicObject]
  5. 3BDLΞϓϦέʔγϣϯ > show-method Rails::Application#call def call(env) env["ORIGINAL_FULLPATH"] = build_original_fullpath(env) env["ORIGINAL_SCRIPT_NAME"]

    = env["SCRIPT_NAME"] super(env) end > show-method Rails::Engine#call def call(env) env.merge!(env_config) if env['SCRIPT_NAME'] env.merge! "ROUTES_#{routes.object_id}_SCRIPT_NAME" => env['SCRIPT_NAME' end app.call(env) end
  6. > Rails.application.middleware => #<ActionDispatch::MiddlewareStack:0x007fe97bcbaf68 @middlewares= [Rack::Sendfile, ActionDispatch::Static, Rack::Lock, #<ActiveSupport::Cache::Strategy::LocalCache::Middleware:0x007fe97e35cc70>, Rack::Runtime,

    Rack::MethodOverride, ActionDispatch::RequestId, Rails::Rack::Logger, ActionDispatch::ShowExceptions, ActionDispatch::DebugExceptions, ActionDispatch::RemoteIp, ActionDispatch::Reloader, ActionDispatch::Callbacks, ActiveRecord::Migration::CheckPending, ActiveRecord::ConnectionAdapters::ConnectionManagement, ActiveRecord::QueryCache, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, ActionDispatch::ParamsParser, Rack::Head, Rack::ConditionalGet, Rack::ETag]>
  7. require 'action_dispatch'! ! header = {'Content-Type' => 'text/html'}! ! routes

    = ActionDispatch::Routing::RouteSet.new! routes.draw do! get 'hello', to: -> env { [200, header, ['hello']] }! get 'goodbye', to: -> env { [200, header, ['goobye']] }! root to: -> env { [200, header, ['Hiroshima Okayama .rb']]}! end! ! Rack::Handler.default.run routes, Port: 3000