Webã§ä½¿ããmrubyã·ã¹ãã ããã°ã©ãã³ã°å ¥é
- ä½è :è¿è¤å®æºæ
- çºå£²æ¥: 2020/11/25
- ã¡ãã£ã¢: Kindleç
ä¹ ãã¶ãã®èªæ¸ææ³ã§ããã©ãããèªæ¸ææ³ã¯ãã¯ãã°ã¨ããå«ãã¦4å¹´ã¶ããããã£ã½ãã¦ãããæ°å¹´ã®èªæ¸ããªãã表ãã¦ãã¾ãã
æ¬æ¸ã¯mrubyã¨ã·ã¹ãã ããã°ã©ãã³ã°ã®çºå±ã«å¤§ããè²¢ç®ããè¯æ¸ã§ããã¨ç¢ºä¿¡ãã¾ãã
æ¬æ¸ã§ã¯mrubyãå©ç¨ãã¦ãã¾ãããããããã®Linuxç°å¢ã§ã®ã¨ã³ã¸ãã¢ãªã³ã°ã«ã¤ãã¦ã®åºç¤ç¥èãå¤ã解説ããã¦ãã¾ããmrubyã«ã¤ãã¦å¦ã³ãã人ã«ã¨ã£ã¦ãã·ã¹ãã ããã°ã©ãã³ã°ã¯è¯ãé¡æã§ãããã·ã¹ãã ããã°ã©ãã³ã°ãå©ç¨ããã人ã«ã¨ã£ã¦ãmrubyãå©ãã«ãªãããããã¾ããã ç¹çãã¹ãã¯ä¸å¯§ãã§ããæ¬æ¸ã®è¬è¾ã«ãããéãããã³ãºãªã³ã®ããã®è³æãä¸å°ã«ãã¦ãããããã¾ãã§çè ãé£ã«ã¤ãã¦ãã¦ããã¦ãããã®ãããªé¯è¦ãè¦ãã¾ããæ¬å½ã«ä¸æ©ä¸æ©ä¸å¯§ã«è§£èª¬ããã¦ãããããmrubyãã·ã¹ãã ããã°ã©ãã³ã°ã«éå£ãæãã¦ããæ¹ã§ããå®å¿ãã¦ä¸æ©ã¥ã¤å¦ãã§ãããã¨ãåºæ¥ãããã«é æ ®ããã¦ãã¾ããç§ã¯ç¬å¦ã§ã·ã¹ãã ããã°ã©ãã³ã°ãå¦ã³ã¾ããããæ¬æ¸ã«ãã£ã¦ç¥èã®è§£å度ãã°ãã¨ä¸ããã¾ããã
mrubyã¨ç§
ãã¦ãç§ã¯ãã¤ã¦mrubyã®éçºã«åå ãã¦ãããã¨ãããã¾ããå 容ã¯å°ããéç®±ã®é ãã¤ã¤ããããªãã®ã°ããã§ãæ°ã ãã¯ç¡é§ã«èªèº«ãããã¾ãã ããæ°å¹´ã¯ãã®æ ç±ã®ã»ã¨ãã©ã家æã¨ã¹ãã©ãã¥ã¼ã³2ã«è²»ãããããããã°ããmrubyããã¯è¶³ãé ã®ããããããèªèº«ãä½ã£ãã©ã¤ãã©ãªã®ã¡ã³ããã³ã¹ãç¶ãã¦ãããããã§ããã
ã·ã¹ãã ããã°ã©ãã³ã°ã¨ç§
ç§ãã·ã¹ãã ããã°ã©ãã³ã°ã«èå³ãæã£ããã£ããã¯ãã¾ãã«mrubyããã ã£ãã®ã§ããmrubyã触ã£ã¦ã¿ã¦ãå½æ大é¨åã®æ©è½ããªãã£ãã®ã§æ©ãè åã¡ã¨ã°ããã«ksss/mruby-signalãksss/mruby-file-statãä½ãå§ãã¾ãããä½ã£ã¦ãã¾ã£ãããã«ã¯ä¸éå端ãªãã¨ã¯ã§ããªãã¨ãLinuxããã°ã©ãã³ã°ã¤ã³ã¿ãã§ã¼ã¹ãèªã¿ãªããã©ã¤ãã©ãªã¼ãä½ã£ã¦ããã®ãè¨æ¶ãã¦ãã¾ããä»æãã¨ã·ã¹ãã ããã°ã©ãã³ã°åå¿è ãããããæ¨æºã§ãããã®ãããªã©ã¤ãã©ãªã¼ãä½ãã®ã¯ãå¨ãããè¦ãã大å¤ãããã¾ããã£ãã§ããããç¡ç¥ããã®çªã£èµ°ãã§ãããããªçªã£èµ°ãã®ç²æãã£ã¦ããLinuxããã°ã©ãã³ã°ã¤ã³ã¿ãã§ã¼ã¹ãèªã¿çµããæãããã°ã©ãã¼ã¨ãã¦ä¸ç®å¥ãããªã¨æã£ããã¨ãè¦ãã¦ãã¾ãã
èè ã¨ç§
ç§ãèè ã®udzuraããã«åãã¦åºä¼ã£ãã®ã¯ãæ spicelife社æ代ã«èè ããªãã£ã¹ã«ã¡ãã£ã¨éã³ã«æ¥ã¦ãããã¨ãã®ãã¨ã§ãããç§ã¯èè ã®ãã¨ã¯ç¥ã£ã¦ãã¾ããããèè ã«ã¨ã£ã¦ã¯ç¡åã®ç§ã®ãã¨ãªãç¥ãç±ããªãã ããã¨ãååã¨èè ã楽ããè«ç¬ãã¦ããã®ã横ã§çºãã¦ããäºãè¦ãã¦ãã¾ãã ãã®å¾ã¯ãä»å°ã§è¡ãããRubyKaigi2018ã§è¡ããã How happy they became with H2O/mruby, and the future of HTTP - RubyKaigi 2018 ã¨ããã»ãã·ã§ã³ã®å¾ã§ãåºä¼ãã¾ãããã»ãã·ã§ã³ã®è©±è @i110ãããèè ãç§ã¯ãã©ãã¼ãã¦ããã®ã§ãããã¯é¡ãè¦ãã¦ãããã¤ã¤ã¹ãã©ãã¥ã¼ã³ã®è©±ããããã£ã³ã¹ã¨æã£ã¦ãããã@i110ããã¨èè ã¨ã§çé¢ç®ãªmrubyè«ç¾©ãå§ã¾ã£ãã®ã§ããµããããã¨ãã¦ããèªåãççã身ãå¼ãã次第ã§ãã ãã®å¾ãããããã¾ãã¾èè ã¨4ãªã°ãããä¸ç·ããã¦ãããã£ããã¨ãããã¾ãããã¡ããã¹ãã©ã®è©±ãããã¦ãã¾ããã
ãããªããæ¥ãDMã§çªç¶èè ããé£çµ¡ãæ¥ã¾ããããksss/mruby-file-statãæ¬ã®ä¸ã§ååãåºãã¦ããããï¼ãã¨ãããã®ã§ãããç§ã¯å¿«è«¾ãã¦ããã®æ¬ã®çºå£²ãã¾ã ãã¾ã ãã¨å¾ ã¡ãã³ã¦ãã¾ããã
ããããæ¬ã®ææ³ã«å ¥ãããã§ããã©ã
mrubyã¨ããã°ãçµã¿è¾¼ã¿åããã¨è¬³ããã¦ãã¾ãããã§ã¯ãçµã¿è¾¼ã¿ãã¨ã¯ä½ãªã®ããæ¬æ¸ã§ã¯ãçµã¿è¾¼ã¿ã¨ã¯ããã¼ãã¦ã§ã¢çµã¿è¾¼ã¿ã¨ãã¢ããªã±ã¼ã·ã§ã³çµã¿è¾¼ã¿ã¨ã§å¤§å¥ãããã¨æ¸ããã¦ãããç§ã®ä¸ã®ã¼ãããã¨ããç解ããã£ããé®®æã«ãªãã¾ãããæ¬æ¸ã§ã¯ç¹ã«ã¢ããªã±ã¼ã·ã§ã³çµã¿è¾¼ã¿ã«ã¤ãã¦æ¸ããã¦ãã¾ããmrubyã¨èãã¦ãã¼ãã¦ã§ã¢çµã¿è¾¼ã¿ãã¤ã¡ã¼ã¸ããæ¹ãå¤ãã¨æãããã®ã§ãæ¬æ¸ã¿ã¤ãã«ã®ãWebã§ä½¿ãããã«ã¢ããªã±ã¼ã·ã§ã³çµã¿è¾¼ã¿ã®æ¬ã§ãã£ã¦ãã¼ãã¦ã§ã¢çµã¿è¾¼ã¿ã®æ¬ã§ã¯ãªãã¨ãããã¨ã表ãã¦ããããã«ãæãã¾ãã
"CRubyãæ¸ããã¨ãã§ãã人ã¯ãã»ã¨ãã©å¦ç¿ãªãã§mrubyãæ¸ãå§ãããã¨ãã§ããã¨èãããã¾ã"
誰ã«ãä¼ãããªãã¨ã¯æãã¾ãããç§ã¯æ¬æ¸ã®ãã®è¨è¿°ã«ã²ã©ãæéãåãã¾ããããªããªããããè¨ããããã¨ããããç§ãmrubyã§æ´»åãã¦ããåååã ã£ãããã§ããéç®±ã®é ãã¤ã¤ããããªPRãmrubyãå¨è¾ºã©ã¤ãã©ãªã¼ã«éããã¦ããã ãããã®ã®å¤ãã¯ããã®CRubyã¨ã®äºææ§ãæèãããã®ã§ããããCRubyã¨mrubyã¯åãããã«æ¸ãã°åãããã«åãããªããªãããã¥ã¡ã³ãã¯CRubyãåç §ããã°ããããããããä¸çãç®æãã¦ããã®ã§ããã¡ããç§ãè¡ã£ãæ´»åãªãã¦å¾®ã ãããã®ã§ããã©ããããè¨ã£ã¦ãããããããã«mrubyããªã£ã¦å¬ããæ°æã¡ã§ãã£ã±ãã§ãã
解説ã®ä¸å¯§ã
æ¬æ¸ã®ã¦ãªã¯ãã®è§£èª¬ã®ä¸å¯§ãã«ããã¨ç§ã¯èãã¾ããä¾ãã°ãmrubyãbuildããã ãã®ã¹ãããã§ãã£ã¦ããbuildä¸ã«ä½ãèµ·ãã£ã¦ããã®ããä½ãå®è¡ããã¦ä½ãçæããã¦ä½ã«ä½¿ãããã®ãã¾ã§ä¸å¯§ã«è§£èª¬ããã¦ãã¾ããç§ãªããrakeãããbuildã§ãã¾ããããããã§çµãã£ã¦ãã¾ãã¨ãããæ°ãã¼ã¸ä½¿ã£ã¦ããã®ãã°ã¯mgemããã¦ã³ãã¼ããã¦ãã¦ããã®ãã°ã¯buildãã¦ãã¦ããã®ãã°ã¯ã¢ã¼ã«ã¤ããä½æãã¦ãã¦â¦â¦ã¨ç´°ãã解説ãã¦ãã¾ããããã¦ãã®buildå·¥ç¨ã¯è¦ããã¯å°å³ã§ããmrubyãç解ããä¸ã§å¤§å¤éè¦ã«ãªã£ã¦ããé¨åãªã®ã§ãã ãã®ããã«ãæ¬å½ã«å¤§åãªãã¨ãé£ã°ããä¸å¯§ã«ä¸æ©ä¸æ©èªè ã®é£ã«ç«ã£ã¦è§£èª¬ãã¦ãããã®ããæ¬æ¸æ大ã®é åã§ãã ã¾ããã¯ã¶ã¨ãã°ãä»è¾¼ãã§ããã®ãã°ãä¿®æ£ãã¦ããéç¨ã§ç¥èãå¦ãã§ããã¹ã¿ã¤ã«ãè¦ããã¾ãããã®æ¹ãç¥èã¯å°åºãã§è¦ãããããããªã«ããå®éã«ã³ã¼ããæ¸ããªããç¥èãå¾ã¦ããã¹ãããã«å³ãã¦ããç¾å®çã§ãã
ããªããã®æ·±å ã
æ¬æ¸ã®ããä¸ã¤ã®é åã¯ããªãmrubyãªã®ããããªãã·ã¹ãã ããã°ã©ãã³ã°ãªã®ããã¨ãã£ãããªããã«ããã£ããã¨è§£èª¬ãå ¥ã£ã¦ããç¹ã§ãããã®ããªããã«çããããã®ã§ãå¦ç¿ããä¸ã§éè¦ãªç´å¾æãè£ããã¦ãããå¦ç¿å¹çãé«ãã¦ãã¾ããããã¾ã§ãã£ããã±ã¢ãã¦ããã®ã¯ãèè ã®è±å¯ãªçµé¨ã®ãªããæã§ãããã åæãªããèè ã«ã¤ãã¦èª¿ã¹ããã¦ããã ããã¨ããããã¼ãã§ã¯ãRubyã¨ãã¼ãã§ã¯ãRuby on Railsã®èè ã®å ã®ä¸äººã§ãããã¾ããã 「GMOペパボは、憧れの会社だったんです」近藤宇智朗(GMOペパボ株式会社)~Forkwellエンジニア成分研究所 - Forkwell Press ã«ããã¨ç ä¿®ã®çµé¨ãè±å¯ã§ããã£ãããã¾ãã
ããã«ãããªããã ãã§ãªãããããã«ãã±ã¢ãå ¥ã£ã¦ãã¾ãããããããããã¾ãè¡ããªãã£ããããããåå ãããããªãã®ã§èª¿ã¹ã¦ã¿ã¦ãã ãããã®ãããªè¨è¿°ãå¤æ°ã¿ãããèè ã®å¦ã¼ãã¨ãã人ã¸ã®é æ ®ãã¿ããã¦ç´ æµã§ãã
ksss/mruby-file-stat
æ¬æ¸ã§ã¯CRubyã®File::Stat
classãå®è£
ãã¦ããéç¨ããã³ãºãªã³ã§å¦ã¹ãç« ãããã¾ãããFile::Stat
classã®å
è¡äºä¾ã¨ãã¦ksss/mruby-file-statãç´¹ä»ããã ãã¦ãã¾ã(ã¢ãã¼ã«)ãæ¬ãããã¯ãã®GitHubã®Traficãã¼ã¸ã«ããã¾ãã¨ãä¸æ¥ã«100ã200åcloneããã¦ããã®ã§ãç§ãä½ã£ããã®ã«ãã¦ã¯éãããããã¯ãã¨ãªã£ã¦ããã¾ãã
æ¬æ¸ã§ã¯mtimeã«usecã¾ã§å¯¾å¿ãã¦ããè¨è¿°ãããããããããã°ksss/mruby-file-statã¯ã©ããã¦ãã£ããªï¼ãã¨æã£ã¦è¦ã¦ã¿ãã¨usecã«å¯¾å¿ãã¦ããããç§åä½ã¾ã§ããåå¾ã§ãã¦ããªããã¨ã«æ°ãã¤ãã¾ããããã®å¾ãããã¦ã¦usec対å¿ãæ¸ã¾ãã¾ãããæ¬æ¸ã®ãããã§ksss/mruby-file-statãã¯ãªãªãã£ãä¸ãããæ©émrubyçéã¸ã®å½±é¿ãä¸ãã¦ããã¨è¨ã£ã¦ããã§ããããæ¬å½ã«ãããã¨ããããã¾ãã
ã¬ãã¥ã¼
æ¬å½ã«ç´°ããªã¨ããã§ãããåè¶ãªããè¥å¹²ã®ææãããã¦ããã ãã¾ãããã¡ããæ·±ãçç±ããã£ããã話ãç°¡åã«ããããã«ããã¨ç¾å¨ã®ããã«è¨è¿°ãã¦ããã®ããããã¾ããã御容赦ãã ããã
__main__
methodãå¼ã¶ä»æ§ããmrubyã®ä»æ§ãªã®ãmruby-templateã®ä»æ§ãªã®ããåããã«ããã£ãã§ãã- mruby-dir-globã¯ä¸å¿ããã¾ãã
File.open(...).read
ãããFile.read(...)
ã®æ¹ãfdçã«è¯ãã®ã§ã¯ã- Apacheã®åé¡ãªã®ã§é£ããã¨ããã§ãããRequestãªãã¸ã§ã¯ãã«
ap_set_content_type
ããã¨Responseã®content_typeãå¤ããã®ã§ãRequestã®è©±ãªãã ãResponseã®è©±ãªãã ãã§æ··ä¹±ãã¾ããã
èªãã ã ããããã¾ã åå
æ¬æ¸ã¯ãã³ãºãªã³å½¢å¼ã«ãªã£ã¦ãã¾ããã¤ã¾ããã®æ¬ã¯ãå®éã«æãåããã¦èªåã®çµé¨ã¨ãã¦èº«ã«ã¤ãããã¨ã§ãæ¬ã®çã®ç¥èãèªè ã®è¡èã¨ãã¦èº«ã«ã¤ãããã«ãªã£ã¦ãã¾ãã ç§ãã¾ã ä¸éãèªãã ã ããªã®ã§ãå®éã«æãåãããªããæ¬æ¸ã®å 容ãå¦ãã§ãããã¨æãã¾ãã
ä¸å®ã¯ããã¾ãããæ¬æ¸ã«ã¯å¸¸ã«èè ãé£ã«ç«ã£ã¦æãã¦ãããã®ã§ãããã