Rails pluginã®ä½ãæ¹
Rails 0.14ããpluginã®ä»çµã¿ãå°å
¥ãããä»ã¾ã§ã¯ãlibã«ã©ã¤ãã©ãªãç½®ãã¦ãconfig/enviroment.rbã«ããè¨è¿°ãã¦äºã
ãã¨ããé¢åãªæ¹æ³ããvender/plugins以ä¸ã«ãã¡ã¤ã«ãé
ç½®ããã ãã§ãRailsæ¬ä½ã®æ¡å¼µãç°¡åã«å¯è½ã«ãªãã¾ããããã®ä½ãæ¹ãRailsã§RESTãç°¡åã«å®ç¾ããpluginãé¡æã«èª¬æãã¾ãã
ã¾ãã¯é
ç½®ãããã¡ã¤ã«ã§ããã
vender/plugins/ãã©ã°ã¤ã³å/init.rb # å¿ é vender/plugins/ãã©ã°ã¤ã³å/lib/* # pluginã§å©ç¨ããã©ã¤ãã©ãª ãã£ã¬ã¯ããªã¯$LOAD_PATHã«è¿½å ããããå¿ é ã§ã¯ãªã
ã¨ãªãã¾ããé åºã¨ãã¦ã¯config/enviroment.rbãèªã¿è¾¼ã¾ããå¾ã«ãinit.rbãevalã§å®è¡ããã¾ãã
ã§ã¯vender/plugins/restmode/init.rbã«
require_dependency 'rest_filter' ActionController::Base.class_eval do private def self.restmode around_filter RestFilter.new end end
ããvender/plugins/restmode/lib/rest_filter.rbã«
class RestFilter def before(controller) controller.action_name = controller.request.method.to_s end def after(controller); end end
ã¨è¨è¿°ãããã¡ã¤ã«ãè¨ç½®ãã¾ããããã ãã§pluginä½æã¯å®äºã§ããä»ã«ãããã¨ã¯ä½ããªããã§ãï¼ãã¨ã¯é å¸ãããªããã¢ããªã±ã¼ã·ã§ã³ã«å«ãããªãã好ãã«ã©ããã
ãã¦ããã®pluginä½æã§èª¬æããrestmode pluginã§ãããã©ã®ããã«ä½¿ããã¨ããã¨ãcontrollerã«ä¸è¡ restmode ã¨æ¸ãã¨ããã ãã§ãã®controllerã§RESTãç°¡åã«ä½¿ããã¨ãã§ããããã«ãªãã¾ããå ·ä½çã«ã¯ã¡ã½ããã«get, post, delete, putãªã©å種ã¡ã½ãããå®ç¾©ããã ãã§ãHTTPã®GET,POST,DELETE,PUTãå©ãããæã«ã対å¿ããcontrollerã®ã¡ã½ãããå¼ã°ãã¾ãã
class RestController < ApplicationController restmode def get # ... end def post # ... end def delete # ... end def put # ... end end
actionåãåç §ããããã ãã©ãã¨ããå ´åã«ãparams[:action]ã«actionåãå ¥ã£ã¦ããã®ã§å°ãã¾ãããããã§Railsã§ç°¡åã«RESTã¢ã¼ããã¯ãã£ã¢ããªã±ã¼ã·ã§ã³ãä½ãããã§ãããpluginèªä½ã¯åè¨12è¡ã»ã©ã§ããããã®ãããªRailsæ¬ä½ã«æãå ãããã¨ãé常ã«ç°¡åã«ã§ããã®ããRubyã¨ããè¨èªã®æè»ãã¨ãã¬ã¼ã ã¯ã¼ã¯ã®ä»çµã¿ã大å¤è¯ãã§ãã¦ããããã§ãããã
èªåã§pluginãã¤ã³ã¹ãã¼ã«ããã¹ã¯ãªãã
svn headãªRailsã§ã¯ RAILS_ROOT/script/plugin ã¨ããã¹ã¯ãªãããç¨æããã¦ããããã®ã¹ã¯ãªãããå©ç¨ãããã¨ã§
$ ./script/plugin install plugin_name
ã¨ç°¡åã«pluginãã¤ã³ã¹ãã¼ã«ãããã¨ãå¯è½ã§ãããã㯠http://wiki.rubyonrails.org/rails/pages/Plugins ã®ãã¼ã¸ãããã©ã°ã¤ã³ä¸è¦§ãåå¾ããããã解æãã¦æ¯è¼çåæ¥ã§è¡ã£ã¦ãã¾ããsvn headãªrailsã使ã£ã¦ããªã人ã¯ã
http://lesscode.org/2005/10/27/rails-simplest-plugin-manager/
ã§è¨è¿°ããã¦ããæ¹æ³ã§./script/pluginãå©ç¨ãããã¨ãã§ãã¾ãã