Railsæ¬ä½ã®ãgeneratorã®generatorãå¤æ´ãããï¼ï¼
æè¿ãRailsã®ã«ã¹ã¿ã generatorãéã®å¼¾ä¸¸(éçºå¹çãé£èºçã«ä¸ãããã®)ã«ãªããªããã¨æã£ã¦ãããã試ãã¦ãã¾ãããã¾ã®ã¨ãããææã¯ä¸ãã£ã¦ãã¾ããwwwé§èåèå(ã ãããã)ãgeneratorãä½æãããã¨ã«å¯¾ããæ·å±
ãã¨ã¦ãä¸ããã¾ãããã¾ã ãRailsã®ã«ã¹ã¿ã generatorãä½ã£ããã¨ããªãæ¹ã¯ ãã¡ãã®è¨äº(http://d.hatena.ne.jp/kouji0625/20130523/p1) ãåèã«ãã¦ä½ã£ã¦ã¿ã¦ãã ãããã
ãã¦ããããããæ¬é¡ã§ãã
ä»åã®ãé¡
Railsæ¬ä½ã®generatorã®generatorãå¤æ´ãããï¼ï¼
ããããããªãã¤ã¾ãããrails generate generator fooãã§çæãããUSAGEãfoo_generator.rbãä¿®æ£ãããã£ã¦ãã¨ã§ãã
æé
ã¾ãã¯ãRalisæ¬ä½ããgeneratorã®ãã³ãã¬ã¼ããã³ãã¼ãã¾ãã
$ mkdir -p lib/templates/rails/generator $ cp -r ~/.rvm/gems/<ruby_version>@<gemset>/gems/railties-<version>/lib/rails/generators/rails/generator/templates/* lib/templates/rails/generator
ãã¨ã¯ãlib/templates/rails/generator以ä¸ã®ãã¡ã¤ã«ãä¿®æ£ããã ãã§ãã
ããã¨ãrails generate generator fooã§èªåçæããããã¡ã¤ã«ããä¸è¨ã®ã³ãã¼ãããã¡ã¤ã«ãå
ã«ãããã®ã«ãªãã¾ãã
ç°¡åã§ããâª
ãã¾ã
ammeterã使ã£ã¦ããã°(http://d.hatena.ne.jp/kouji0625/20130524/p1)ã以ä¸ã®å 容ã®ãã¡ã¤ã«ãspec/generators/rails/generator/generator_generator_spec.rbã«é ç½®ãããã¨ã§ãã«ã¹ã¿ãã¤ãºããGeneratorGeneratorã®specãæ¸ãã¾ããgeneratorã®specãããã°ãRailsããã¼ã¸ã§ã³ã¢ããããã¨ãã«ããã¡ãã¡rails generateãå®è¡ãã¦åä½ç¢ºèªããªãã¦ãããã¨ããã®ãããããã§ããã
require 'spec_helper.rb' require "rails/generators/rails/generator/generator_generator" describe Rails::Generators::GeneratorGenerator do destination_root = File.expand_path("tmp/spec/generators", Rails.root) before do Rails::Generators::GeneratorGenerator.instance_eval do source_root File.expand_path('lib/templates/rails/generator', Rails.root) end run_generator %w(foo) end describe "lib/generators/foo/foo_generator.rb" do subject { file("lib/generators/foo/foo_generator.rb") } it { should exist } end end
--- åèæ å ±
- Creating and Customizing Rails Generators & Templates - 6 Customizing Your Workflow by Changing Generators Templates: http://guides.rubyonrails.org/generators.html#customizing-your-workflow-by-changing-generators-templates
--- PRåºå
è¨äºãèªãã§ãã ããããããã¨ããããã¾ãããããããããã°ããã®è¨äºã®èè
ãæä¾ãã¦ããç¡æã®ãµã¼ãã¹ãããã£ã¦ãï¼ããã試ããã ããã
- ããã£ã¦ãï¼: http://cocktailq.herokuapp.com/