ããã°ã©ãã®æ°äºã§ãã ä»åã¯ç大好ããRackãã触ã£ã¦ã¿ããã¨æãã¾ãã Rackã¨ã¯ -- Rack: a Ruby WebServer Interface ç°¡åã«è¨ãã¨ãWebãµã¼ãã®å·®ç°ãå¸åããçµ±ä¸çãªAPIãæä¾ããã¤ã³ã¿ã¼ãã§ã¼ã¹ãã§ãã Webãµã¼ãã«ã¯Apache,WEBrick,Mongrelãªã©æ§ã ãªãã®ãããã¾ãã ãããã«åå¥ã«å¯¾å¿ãããã¨ããã¨ãã¬ã¼ã ã¯ã¼ã¯ãã¨ã«Webãµã¼ãããµãã¼ãããã³ã¼ããå¿ è¦ã«ãªãã¾ãã Rackãå©ç¨ããã¨ãã¬ã¼ã ã¯ã¼ã¯ã¨Webãµã¼ãã®éãè¯ãããã«åããã£ã¦ããã¾ãã [ãã©ã¦ã¶] [Webãµã¼ã] [Rack] [ãã¬ã¼ã ã¯ã¼ã¯] [Webã¢ããª] Rack Middleware -- ä¸è¨ã«ä¸ããããã«ãWebãµã¼ãã®å·®ç°ãå¸åãããã ãã§ãç´ æ´ããã§ãããããä¸ã¤ã®å©ç¹ãããã¾ãã ããã¯Rack Middlewareã®ä»çµã¿ã§ãã Rack Middlewareãå©ç¨ãããã¨ã«ããããµã¼ãã¨ã¢ããªã±ã¼ã·ã§ã³ã®éã§ã¡ãã£ã¨ããå¦çãè¡ããã¨ãã§ãã¾ãã ä¾ãã°ãæ¡ä»¶ã«å¿ããURLã®æ¸ãæãããCookieã®å¦çãªã©ãRack Middlewareãå©ç¨ãããã¨ã§ç°¡åã«ããã¤Webãµã¼ãã«ä¾åãããã¨ãªãè¡ããããã«ãªãã¾ãã ã¨ããããRackãåããã¦ã¿ã -- gemã§rackãã¤ã³ã¹ãã¼ã«ãã¾ãã $ gem install rack 以ä¸ã®ãã¡ã¤ã«ãconfig.ruã¨ãã¦ä½æãã¾ãã rackupã³ãã³ãã§èµ·åãã¾ãã $ rackup config.ru ããã§localhost:9292ã«ã¢ã¯ã»ã¹ããã¨Hello, world!ã表示ããããã¨æãã¾ãã æ¢ããã¨ãã¯Ctrl-Cã¨ãã§æ¢ãã¦ãã ããã ããã©ã«ãã ã¨WEBrickãèµ·åãã¾ããã以ä¸ã®ããã«ããã°ä»ã®ãµã¼ãã¼ãèµ·åãããã¨ãå¯è½ã§ãã $ rackup config.ru -s SERVER Rackã¯ãã®ããã«config.ruã«è²ã æ¸ãã®ã§ããããã®ã³ã¼ãã§ã¯å¦çãä¸ç·ã«ãªã£ã¦ãã¾ãã ãªã®ã§æ¬¡ã¯config.ruã«æ¸ãã¹ãè¨å®ã¨ã¢ããªã±ã¼ã·ã§ã³é¨åãåå²ãã¾ãããã Rackã¢ããªãæ¸ãã¦ã¿ã -- ãã£ããè¨ã£ã¦ãã¾ãã¨ä»¥ä¸ã®è¦ç´ ãæºããã¦ããã°Rackã¢ããªã¨ãªãã¾ãã - callã¨ããã¡ã½ãããæã£ã¦ããã㨠- callã¡ã½ããã®å¼æ°ã¨ãã¦env(ç°å¢å¤æ°ã®ããã·ã¥)ãåãã¨ãã㨠- callã¡ã½ããã¯ï¼æ¬¡ã®è¦ç´ ãå«ãã¬ã¹ãã³ã¹ãè¿ããã㨠- ã¹ãã¼ã¿ã¹ã³ã¼ã - ã¬ã¹ãã³ã¹ããã(Hash) - ã¬ã¹ãã³ã¹ããã£(Array) ããããæºããããã«ä¿®æ£ãã¦ã¿ã¾ããã 両æ¹ã®ãã¡ã¤ã«ãåãå ´æã«ããã¦å ç¨ã¨åæ§ã«localhost:9292ã¸ã¢ã¯ã»ã¹ããã¨ããHello, Rack Application!ãã¨è¡¨ç¤ºããããã¨æãã¾ãã Rack Middlewareãå©ç¨ãã -- æå¾ã«Rack Middlewareãå ¥ãã¦ã¿ã¾ãããã ããã©ã«ãã§ãããã¤ãå©ç¨ã§ãããã®ãããã¾ãã ä»åã¯Basicèªè¨¼ã®Rack Middlewareã§ããRack::Auth::Basicãå©ç¨ãã¦ã¿ã¾ãããã config.ruã以ä¸ã®ããã«æ¸ãæãã¾ãã ãµã¼ãã¼ãåèµ·åãã¦localhost:9292ã¸ã¢ã¯ã»ã¹ãããã¨Basicèªè¨¼ã®ãã¤ã¢ãã°ãåºã¦ãããã¨æãã¾ãã config.ruã§æå®ããã¦ã¼ã¶ã¼ããã¹ã¯ã¼ãã§èªè¨¼ã§ãã¾ãã ã¾ã¨ã -- ä»åã®é¡æã®Rackã¯ãã¬ã¼ã ã¯ã¼ã¯éçºè ã®ãããªäººã§ãªããã°æ®æ®µãã¾ã触ããã¨ã®ãªãç®æã§ã¯ããã¾ãããRack Middlewareã¯é常ã®éçºã§ããã使ãã¦å½¹ç«ã¤ãã®ã沢山ããã¾ãã ã¾ããRack MiddlewareãRackã¢ããªãªã®ã§ç°¡åã«ä½æãããã¨ãã§ãã¾ãã ä»åã¯Rack Middlewareã®ä½æã¾ã§ã¯è¡ãã¾ããããç°¡åã«ä½ãããããç解ãããæ·±ã¾ããã¨ééããªãã®ã§æ¯éä¸åº¦ä½ã£ã¦ã¿ããã¨ããå§ããã¾ãã è£è¶³ -- Rackãã¤ã³ã¹ãã¼ã«ããéã«gemãå©ãã¾ããããBundlerãå©ç¨ããããã«ããã°ãã®ã¾ã¾Herokuä¸ã§ä»åã®ãµã³ãã«ãåãããã¨ãå¯è½ã§ãã åèãµã¤ã -- 5åã§ãããRack Ruby Freaks Loungeï¼ç¬¬23åãRackã¨ã¯ä½ãï¼1ï¼Rackã®çã¾ããèæ¯ï½gihyo.jp ⦠æè¡è©è«ç¤¾
Rackã¨éã¶
è¨äºã¿ã¤ãã«ã¨URLãã³ãã¼ãã