Kristian Mandrup
2010-Jan-28 16:48 UTC
Creating a rails 3 app generator executable using thor
For inspiration I have been looking into rails 3.0pre I found this in the file bin/rails -- ... require ''rails/generators'' require ''generators/rails/app/app_generator'' Rails::Generators::AppGenerator.start -- framework.task -- ... desc "Applies the template supplied by LOCATION=/path/to/template" task :template do template = ENV["LOCATION"] template = File.expand_path(template) if template !~ %r{\A[A-Za-z] [A-Za-z0-9+\-\.]*://} require ''rails/generators'' require ''generators/rails/app/app_generator'' generator = Rails::Generators::AppGenerator.new [ Rails.root ], {}, :destination_root => Rails.root generator.apply template, :verbose => false end namespace :update do def invoke_from_app_generator(method) require ''rails/generators'' require ''generators/rails/app/app_generator'' generator = Rails::Generators::AppGenerator.new ["rails"], { :with_dispatchers => true }, :destination_root => Rails.root generator.invoke(method) end desc "Update config/boot.rb from your current rails install" task :configs do invoke_from_app_generator :create_boot_file invoke_from_app_generator :create_config_files end desc "Update Prototype javascripts from your current rails install" task :javascripts do invoke_from_app_generator :create_prototype_files end desc "Add new scripts to the application script/ directory" task :scripts do invoke_from_app_generator :create_script_files end -- and in railties3.0pre.gemspec -- .. s.default_executable = %q{rails} s.executables = ["rails"] .. -- So I assume, to make a gem executable, you simply need to define the executables, put an executable in the bin folder, fx bin/my_executable and have that executable require and then call start on the application generator? Thanks! Kristian -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Kristian Mandrup
2010-Jan-28 17:40 UTC
Re: Creating a rails 3 app generator executable using thor
except I run into the following issue module Nifty module Generators class ScaffoldGenerator < Base ... def initialize(*args, &block) super args_for_c_m.each do |arg| if arg == ''!'' options[:invert] = true <<<<<< line 53 ... if @model_attributes.empty? options[:skip_model] = true <<<<<<<< end -- $ nifty_scaffold blip /opt/local/lib/ruby/gems/1.9.1/gems/railties-3.0.pre/lib/rails/vendor/ thor-0.12.3/lib/thor/core_ext/hash_with_indifferent_access.rb:26:in ` [] ='': can''t modify frozen hash (RuntimeError) from /opt/local/lib/ruby/gems/1.9.1/gems/railties-3.0.pre/lib/ rails/ vendor/thor-0.12.3/lib/thor/core_ext/hash_with_indifferent_access.rb: 26:in `[]='' from /opt/local/lib/ruby/gems/1.9.1/gems/ very_nifty_generators-0.1.2/ lib/generators/nifty/scaffold/scaffold_generator.rb:53:in `initialize'' -- Is there a nice way to fix this? Do I have to create a non-frozen custom options collection or someone has a better idea? Kristian -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Kristian Mandrup
2010-Jan-28 22:17 UTC
Re: Creating a rails 3 app generator executable using thor
I fixed it with a pretty ugly hack :P def initialize(*args, &block) super @my_options ||= {} ... if arg == ''!'' @my_options[:invert] = true ... if @model_attributes.empty? @my_options[:skip_model] = true def do_skip_model? options.skip_model? || @my_options[:skip_model] end def do_invert? options.invert? || @my_options[:invert] end def create_model unless do_skip_model? ... I''m sure there must be better ways around this! I have also managed to create executables for all my generators! http://github.com/kristianmandrup/very_nifty_generators Enjoy! -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.