Skip to content

Actions

chikamichi edited this page Aug 2, 2011 · 8 revisions

Thor comes with several actions which helps with script and generator tasks. You might be familiar with them since some came from Rails Templates. They are: say, ask, yes?, no?, add_file, remove_file, copy_file, template, directory, inside, run, inject_into_file and a couple more.

To use them, you just need to include Thor::Actions in your Thor classes:

class App < Thor
  include Thor::Actions
  # tasks
end

Some actions like copy file requires that a class method called source_root is defined in your class. This is the directory where your templates should be placed. Be sure to check the documentation on Thor::Actions. For instance:

class App < Thor
  include Thor::Actions

  def self.source_root
    File.dirname(__FILE__)
  end
end
Clone this wiki locally