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

Railsサーバ起動の裏側

 Railsサーバ起動の裏側

ヒカラボさんのイベントで発表したスライドです

Shinichi Maeshima

February 27, 2018
Tweet

More Decks by Shinichi Maeshima

Other Decks in Programming

Transcript

  1. みんな大好き Ruby on Rails • Railsのお作法(レール)に乗ってるだけで、意識せずにべ んり技術を使えていて最高 • 例えばセキュリティ的には •

    HTMLの自動エスケープ • CSRFチェック用のトークンを自動で追加 • レスポンスヘッダに自動でセキュアになるやつを追加
  2. bin/rails #!/usr/bin/env ruby begin load File.expand_path('../spring', __FILE__) rescue LoadError =>

    e raise unless e.message.include?('spring') end APP_PATH = File.expand_path('../config/application', __dir__) require_relative '../config/boot' require 'rails/commands'
  3. railties/lib/rails/ commands.rb require "rails/command" aliases = { "g" => "generate",

    "d" => "destroy", "c" => "console", "s" => "server", "db" => "dbconsole", "r" => "runner", "t" => "test" } command = ARGV.shift command = aliases[command] || command Rails::Command.invoke command, ARGV
  4. APP_PATHはbin/railsで 定義してた #!/usr/bin/env ruby begin load File.expand_path('../spring', __FILE__) rescue LoadError

    => e raise unless e.message.include?('spring') end APP_PATH = File.expand_path('../config/application', __dir__) require_relative '../config/boot' require 'rails/commands'
  5. railties/lib/rails/ all.rb require "rails" %w( active_record/railtie active_storage/engine action_controller/railtie action_view/railtie action_mailer/railtie

    active_job/railtie action_cable/engine rails/test_unit/railtie sprockets/railtie ).each do |railtie| begin require railtie rescue LoadError end end
  6. railties/lib/rails.rb module Rails class << self @application = @app_class =

    nil attr_writer :application def application @application ||= (app_class.instance if app_class) end # The Configuration instance used to configure the Rails environment def configuration application.config end def root application && application.config.root end def env @_env ||= ActiveSupport::StringInquirer.new( ENV["RAILS_ENV"].presence || ENV["RACK_ENV"].presence || “development" ) end end end
  7. activerecord/lib/ active_record/railtie.rb module ActiveRecord class Railtie < Rails::Railtie initializer "active_record.initialize_timezone"

    do ActiveSupport.on_load(:active_record) do self.time_zone_aware_attributes = true self.default_timezone = :utc end end initializer "active_record.logger" do ActiveSupport.on_load(:active_record) { self.logger ||= ::Rails.logger } end initializer "active_record.check_schema_cache_dump" do # ... end end end