Google App Engine 㧠Rails ãåããã¦ã¿ã
Google App Engine (ä»¥ä¸ GAE) 㧠Java ã使ããããã«ãªã£ãããã JRuby ãåä½ããããã«ãªãã¾ããã
JRuby on GAE 㧠Rails ãåãããï¼ã¨ãããã¨ã§ããã¡ãã¡ã§è©¦ã¿ããªããã¦ãã¾ãã
ã£ã¦ãã¨ã§ãå
éã®è¨äºã¯ãã£ã±ããããã©ãæãåãããªãã¨ããããªãã®ã§èªåã§ãã£ã¦ã¿ã¾ããã
æ¡ã®å®è²ã
å¼ã£ããã£ãã®ã§ã¡ã¢ã¡ã¢ã
æ¦è¦
ã¾ããåãã¦ãã (ãã¶ã) ãµã³ãã«ã¯ä»¥ä¸ã® URL ã
ãã¢: http://hello-gae-gom.appspot.com/
ã½ã¼ã¹: http://github.com/gom/hello-gae-gom/tree/master
ããã«ã¡ãï¼ã¨ã表示ããããåãã¦ãã¨æãã¾ãã
åããªãç¶æ
ã«ãªã£ã¦ããããããªããã
ãã¼ã¿ã¯ä½ãä¿åã»èªã¿åºãããã Controller ããããã¹ããåºåãã¦ããã ãã§ãã
å¶é
GAE ã«ã¯ããã¤ãã®å¶éãããã¾ãã
- ãã¡ã¤ã«æ°ã¯ 1000 ã¾ã§
- ãã¡ã¤ã«ãµã¤ãºãä¸éããã
ãããã®å¶éãã¯ãªã¢ã㦠Rails ãåããå¿ è¦ãããã¾ãã
ä½ããã°ããã®ï¼
ãããã¨ã¯ãããããã 8 å²ããã㯠Rails Templete ããã£ã¦ããã¾ãã
ãªããä»å㯠DataStore ã¯è¡ã£ã¦ã¾ããã
- ã½ããã®æºå
- Rails ã¢ããªã®ä½æ
- æ®éã«ã¢ããªãä½æ
- GAE ç¨ã«è¨å®ãå¤æ´
- lib ãç¨æ
- Rails ã®ä¸è¦ãªãã¡ã¤ã«ãåé¤
- GAE ç¨ã® XML ãã¡ã¤ã«ãä½æ
- Warbler ã§ãµã¼ãã¬ããå
- ãããã¤
ã¨ããããã§ã以ä¸ã§ç°¡åã«æé ãç´¹ä»ã
ã½ããã®æºå
jruby ã¤ã³ã¹ãã¼ã«
github ãã jruby ã git clone ãããã«ããã¾ãã
ãã¨ã§ lib ã¨ãã¦ä½¿ã jar ãã¡ã¤ã«çæãè¡ãã¾ãã
$git clone git://github.com/jruby/jruby.git $cd jruby $ant $ant jar-complete #=> lib/jar-complete.jar ãçæ
ã¾ããã³ãã³ããç°¡ç¥åããããã«ã jruby ã® PATH ãè¨å®ãã¦ããã¾ãã
#.zshrc export $JRUBY_PATH=/path/to/bin/jruby
jruby ãåå²ãã jar ãä½æãã
ä¸è¨ã®ã¹ã¯ãªãã㧠jar ãã¡ã¤ã«ãåå²ãã¾ãã
jruby-core.jar 㨠jruby-stdlib.jar ãçæããã¾ãã
via:ぽかぽか陽気 - ずっと君のターン
#!/bin/sh rm -rf jruby-core.jar rm -rf ruby-stdlib.jar rm -rf tmp_unpack mkdir tmp_unpack cd tmp_unpack jar xf ../jruby-complete.jar cd .. mkdir jruby-core mv tmp_unpack/org jruby-core/ mv tmp_unpack/com jruby-core/ mv tmp_unpack/jline jruby-core/ mv tmp_unpack/jay jruby-core/ mv tmp_unpack/jruby jruby-core/ cd jruby-core jar cf ../jruby-core.jar . cd ../tmp_unpack jar cf ../ruby-stdlib.jar . cd .. rm -rf jruby-core rm -rf tmp_unpack rm -rf jruby-complete.jar
jruby-rack ã®ç¨æ
jruby-rack-x.x.x.jar ãä½æãã¾ãã
$ git clone git://github.com/nicksieger/jruby-rack.git $ cd jruby-rack $ jruby -S rake SKIP_SPECS=true
warbler ã®ã¤ã³ã¹ãã¼ã«
Rails ã¢ããªã Java ã¢ããªã±ã¼ã·ã§ã³ãµã¼ãã«ãããã¤ããããã® gem ãã¤ã³ã¹ãã¼ã«ãã¾ãã
*1
$jruby -S gem install warbler
google app engine java sdk ããã¦ã³ãã¼ã
Google æ§ã®è¨ãéãã«ããã¨è½ã¨ããã¨æãã¾ãã
appengine-api.jar ã¨ãããã¤ã¹ã¯ãªããã使ãã
Rails ã¢ããªã®ä½æ
Rails ã¤ã³ã¹ãã¼ã«
ri ã rdoc ã¯ãã¡ã¤ã«æ°ãå¢ããã ããªã®ã§ãããªã
$jruby -S gem install rails --no-ri --no-rdoc
ã¢ããªã®ä½æ
ã³ã³ããã¼ã©ãã render :text ããã ã
$jruby -S rails hello-gae-gom $cd hello-gae-gom $jruby -S script/generate controller index $vim app/controllers/index_controller.rb
ã¢ããªè¨å®
ã«ã¼ã¿ãè¨å®
$vim config/routes.rb map.root :controller => 'index'
protect_from_forgery ãã³ã¡ã³ãã¢ã¦ã
ãªãã ã使ããªããããã®ã§ãã³ã¡ã³ãã¢ã¦ãã
$vim app/controllers/apprication_controller.rb #protect_from_forgery # See ActionController::RequestForgeryProtection for details
active record ã¯ä½¿ããªã
$vim config/environment.rb config.frameworks -= [ :active_record]
lib ãç¨æ
ããã¾ã§ã®æé ã§ä½æãã jar ãã¾ã¨ãã¦$RAILS_ROOT/lib ã«å ¥ãã
Rails ã®ä¸è¦ãªãã¡ã¤ã«ãåé¤
rm -rf test/ rm -rf doc/ rm -rf vendor/rails/railties/doc rm -rf vendor/rails/railties/html rm -rf vendor/rails/railties/bin rm -rf vendor/rails/railties/builtin rm -rf vendor/rails/railties/environments rm -rf vendor/rails/railties/dispatches rm -rf vendor/rails/activerecord/ rm -rf vendor/rails/actionmailer/test rm -rf vendor/rails/actionpack/test rm -rf vendor/rails/activeresource/test rm -rf vendor/rails/activesupport/test rm -rf vendor/rails/railties/test
XML ãä½æ
# appengine-web.xml <?xml version="1.0" encoding="utf-8"?> <appengine-web-app xmlns="http://appengine.google.com/ns/1.0"> <application>#{app_name}</application> <version>2</version> <static-files /> <resource-files /> <sessions-enabled>true</sessions-enabled> <system-properties> <property name="jruby.management.enabled" value="false" /> <property name="os.arch" value="" /> <property name="jruby.compile.mode" value="JIT"/> <!-- JIT|FORCE|OFF --> <property name="jruby.compile.fastest" value="true"/> <property name="jruby.compile.frameless" value="true"/> <property name="jruby.compile.positionless" value="true"/> <property name="jruby.compile.threadless" value="false"/> <property name="jruby.compile.fastops" value="false"/> <property name="jruby.compile.fastcase" value="false"/> <property name="jruby.compile.chainsize" value="500"/> <property name="jruby.compile.lazyHandles" value="false"/> <property name="jruby.compile.peephole" value="true"/> </system-properties> </appengine-web-app>
warble ã®æºå
$jruby -S warble config $jruby -S warble pluginize $vim config/warble.rb Warbler::Config.new do |config| config.dirs = %w (app config lib log vendor tmp) config.includes = FileList["appengine-web.xml"] config.java_libs = [] config.gem_dependencies = true config.webxml.jruby.min.runtimes = 1 config.webxml.jruby.max.runtimes = 1 config.webxml.jruby.init.serial = true end
ãããã¤å®è¡
ãã¡ã¤ã«æ°ã®ãã§ãã¯
$find . -type f | wc -l
ã¢ãããã¼ã
$ appengine-java-sdk/bin/appcfg.sh udpate tmp/war
åä½ç¢ºèª
ã¾ã¨ã
以ä¸ã JRuby on Rails on GAE ããã£ã¦ã¿ã¾ããã
Rails2.3.2 以éãªããã¢ããªä½ææã«ãã³ãã¬ã¼ããé©ç¨ãããã¨ã§ãä½æ¥ãç°¡ç¥åã§ãã¾ãã
$jruby -S rails -m template.rb APPNAME
ä¸è¨ã§ä½æãããµã³ãã«ã®ã¢ããªã¨ãã³ãã¬ã¼ããä¸è¨ã«ç½®ãã¦ã¾ãã
ããã£ããåèã«ãã¦ãã ããã
http://github.com/gom/hello-gae-gom/tree/master
è¿½è¨ 2009/04/27 08:20
ãã¢ãã¨ã©ã¼ã«ãªã£ã¦ãã¾ããããåã¢ãããããç´ãã¾ããã
ã¨ã©ã¼ãã°ã«ã¯rackãã¨ã©ã¼åãã¦ãããã ãã©ãä»ã®ã¨ããåå ãããããããã
æéçµã£ã¦ããã¾ãè¦ããªããªã£ã¦ããããã®æã«ãã£ãã調ã¹ããã