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
--

Aha! Require the app generator and then start it :)

then in *framework.task*
--
...
  desc "Applies the template supplied by LOCATION=/path/to/template"
  task :template do
    ...
    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
--

Here the utility method invoke_from_app_generator requires the app
generator and invokes a specific method.
Specific tasks then use this utility method to execute specific parts
of the app generator as needed...

and in railties3.0pre.gemspec
--
..
  s.default_executable = %q{rails}
  s.executables = ["rails"]
..
--

Defines the executable rails found in the *bin* folder

So I assume, to make a gem executable, you simply need to
1. define the executables in the gemspec
2. put an executable in the bin folder, fx bin/my_executable
3. have that executable require a generator and then call start on the
generator
4. install the gem
5. run the executable passing in any defined arguments as per the
generator

Commens, ideas, suggestions?

Thanks!

Kristian

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to