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

そうだ Rack 作ろう。

そうだ Rack 作ろう。

社内勉強会でRackについて説明した際の資料です。

rince

July 30, 2014
Tweet

More Decks by rince

Other Decks in Programming

Transcript

  1. 3BDLͷ໾ׂ Passenger Unicorn Thin Mongrel Rails Sinatra Ramaze Merb Application

    Server Framework ΠϯλʔϑΣʔεͷ౷ҰʹΑΓɺ ϑϨʔϜϫʔΫʗAPαʔόؒͷ૊Έ߹ΘͤΛࣗ༝ʹ͢Δ
  2. 3BDLΞϓϦΛ࡞ͬͯΈΑ͏ class RackApp def call(env) [200, {'Content-Type' => 'text/html'}, ["Hello,

    Rack world!"]] end end run RackApp.new DPOpHSV ! $ rackup config.ru
  3. 3BDLϛυϧ΢ΣΞΛ࡞ͬͯΈΑ͏ class UpcaseAll def initialize(app) @app = app end def

    call(env) code, headers, body = @app.call(env) body.each {|part| part.upcase! } [code, headers, body] end end class RackApp #... end use UpcaseAll run RackApp.new DPOpHSV
  4. (FNͷ࡞Γํ require "my_first_gem/version" module MyFirstGem class UpcaseAll #... end end

    $ bundle gem my_first_gem (FNͷ਽ܗΛ࡞Δ ֓ཁΛHFNTQFDʹॻ͘ ϥΠϒϥϦΛॻ͘ (FNΛϏϧυ͢Δ $ rake build
  5. 6OJDPSOͷ࢖͍ํ worker_processes 2 listen 9292 stderr_path File.expand_path('unicorn.log', File.dirname(__FILE__)) stdout_path File.expand_path('unicorn.log',

    File.dirname(__FILE__)) pid File.expand_path('unicorn.pid', File.dirname(__FILE__)) $ echo “gem ‘unicorn’” >> Gemfile $ bundle install 6OJDPSOΛΠϯετʔϧ ઃఆϑΝΠϧʢVOJDPSODPOGʣΛ༻ҙ͢Δ 6OJDPSOΛىಈ͢Δ 6OJDPSOΛఀࢭ͢Δ $ kill -QUIT `cat unicorn.pid` $ unicorn -c unicorn.conf -D