Module Thor::Actions
In: lib/bundler/vendor/thor/actions/inject_into_file.rb
lib/bundler/vendor/thor/actions/file_manipulation.rb
lib/bundler/vendor/thor/actions/empty_directory.rb
lib/bundler/vendor/thor/actions/directory.rb
lib/bundler/vendor/thor/actions/create_file.rb
lib/bundler/vendor/thor/actions.rb

Methods

Classes and Modules

Module Thor::Actions::ClassMethods

Attributes

behavior  [RW] 

Public Class methods

Extends initializer to add more configuration options.

Configuration

behavior<Symbol>:The actions default behavior. Can be :invoke or :revoke. It also accepts :force, :skip and :pretend to set the behavior and the respective option.
destination_root<String>:The root directory needed for some actions.

Public Instance methods

add_file(destination, *args, &block)

Alias for create_file

Append text to a file. Since it depends on inject_into_file, it‘s reversible.

Parameters

path<String>:path of the file to be changed
data<String>:the data to append to the file, can be also given as a block.
config<Hash>:give :verbose => false to not log the status.

Example

  append_file 'config/environments/test.rb', 'config.gem "rspec"'

  append_file 'config/environments/test.rb' do
    'config.gem "rspec"'
  end

Loads an external file and execute it in the instance binding.

Parameters

path<String>:The path to the file to execute. Can be a web address or a relative path from the source root.

Examples

  apply "http://gist.github.com/103208"

  apply "recipes/jquery.rb"

Changes the mode of the given file or directory.

Parameters

mode<Integer>:the file mode
path<String>:the name of the file to change mode
config<Hash>:give :verbose => false to not log the status.

Example

  chmod "script/*", 0755

Copies the file from the relative source to the relative destination. If the destination is not given it‘s assumed to be equal to the source.

Parameters

source<String>:the relative path to the source root.
destination<String>:the relative path to the destination root.
config<Hash>:give :verbose => false to not log the status.

Examples

  copy_file "README", "doc/README"

  copy_file "doc/README"

Create a new file relative to the destination root with the given data, which is the return value of a block or a data string.

Parameters

destination<String>:the relative path to the destination root.
data<String|NilClass>:the data to append to the file.
config<Hash>:give :verbose => false to not log the status.

Examples

  create_file "lib/fun_party.rb" do
    hostname = ask("What is the virtual hostname I should use?")
    "vhost.name = #{hostname}"
  end

  create_file "config/apach.conf", "your apache config"

Returns the root for this thor class (also aliased as destination root).

Sets the root for this thor class. Relatives path are added to the directory where the script was invoked and expanded.

Copies recursively the files from source directory to root directory. If any of the files finishes with .tt, it‘s considered to be a template and is placed in the destination without the extension .tt. If any empty directory is found, it‘s copied and all .empty_directory files are ignored. Remember that file paths can also be encoded, let‘s suppose a doc directory with the following files:

  doc/
    components/.empty_directory
    README
    rdoc.rb.tt
    %app_name%.rb

When invoked as:

  directory "doc"

It will create a doc directory in the destination with the following files (assuming that the app_name is "blog"):

  doc/
    components/
    README
    rdoc.rb
    blog.rb

Parameters

source<String>:the relative path to the source root.
destination<String>:the relative path to the destination root.
config<Hash>:give :verbose => false to not log the status. If :recursive => false, does not look for paths recursively.

Examples

  directory "doc"
  directory "doc", "docs", :recursive => false

Creates an empty directory.

Parameters

destination<String>:the relative path to the destination root.
config<Hash>:give :verbose => false to not log the status.

Examples

  empty_directory "doc"

Receives a file or directory and search for it in the source paths.

Gets the content at the given address and places it at the given relative destination. If a block is given instead of destination, the content of the url is yielded and used as location.

Parameters

source<String>:the address of the given content.
destination<String>:the relative path to the destination root.
config<Hash>:give :verbose => false to not log the status.

Examples

  get "http://gist.github.com/103208", "doc/README"

  get "http://gist.github.com/103208" do |content|
    content.split("\n").first
  end

Run a regular expression replacement on a file.

Parameters

path<String>:path of the file to be changed
flag<Regexp|String>:the regexp or string to be replaced
replacement<String>:the replacement, can be also given as a block
config<Hash>:give :verbose => false to not log the status.

Example

  gsub_file 'app/controllers/application_controller.rb', /#\s*(filter_parameter_logging :password)/, '\1'

  gsub_file 'README', /rake/, :green do |match|
    match << " no more. Use thor!"
  end

Goes to the root and execute the given block.

Injects text right after the class definition. Since it depends on inject_into_file, it‘s reversible.

Parameters

path<String>:path of the file to be changed
klass<String|Class>:the class to be manipulated
data<String>:the data to append to the class, can be also given as a block.
config<Hash>:give :verbose => false to not log the status.

Examples

  inject_into_class "app/controllers/application_controller.rb", "  filter_parameter :password\n"

  inject_into_class "app/controllers/application_controller.rb", ApplicationController do
    "  filter_parameter :password\n"
  end

Injects the given content into a file. Different from gsub_file, this method is reversible.

Parameters

destination<String>:Relative path to the destination root
data<String>:Data to add to the file. Can be given as a block.
config<Hash>:give :verbose => false to not log the status and the flag for injection (:after or :before) or :force => true for insert two or more times the same content.

Examples

  inject_into_file "config/environment.rb", "config.gem :thor", :after => "Rails::Initializer.run do |config|\n"

  inject_into_file "config/environment.rb", :after => "Rails::Initializer.run do |config|\n" do
    gems = ask "Which gems would you like to add?"
    gems.split(" ").map{ |gem| "  config.gem :#{gem}" }.join("\n")
  end

Do something in the root or on a provided subfolder. If a relative path is given it‘s referenced from the current root. The full path is yielded to the block you provide. The path is set back to the previous path when the method exits.

Parameters

dir<String>:the directory to move to.
config<Hash>:give :verbose => true to log and use padding.

Prepend text to a file. Since it depends on inject_into_file, it‘s reversible.

Parameters

path<String>:path of the file to be changed
data<String>:the data to prepend to the file, can be also given as a block.
config<Hash>:give :verbose => false to not log the status.

Example

  prepend_file 'config/environments/test.rb', 'config.gem "rspec"'

  prepend_file 'config/environments/test.rb' do
    'config.gem "rspec"'
  end

Returns the given path relative to the absolute root (ie, root where the script started).

remove_dir(path, config={})

Alias for remove_file

Removes a file at the given location.

Parameters

path<String>:path of the file to be changed
config<Hash>:give :verbose => false to not log the status.

Example

  remove_file 'README'
  remove_file 'app/controllers/application_controller.rb'

Executes a command returning the contents of the command.

Parameters

command<String>:the command to be executed.
config<Hash>:give :verbose => false to not log the status. Specify :with to append an executable to command executation.

Example

  inside('vendor') do
    run('ln -s ~/edge rails')
  end

Executes a ruby script (taking into account WIN32 platform quirks).

Parameters

command<String>:the command to be executed.
config<Hash>:give :verbose => false to not log the status.

Holds source paths in instance so they can be manipulated.

Gets an ERB template at the relative source, executes it and makes a copy at the relative destination. If the destination is not given it‘s assumed to be equal to the source removing .tt from the filename.

Parameters

source<String>:the relative path to the source root.
destination<String>:the relative path to the destination root.
config<Hash>:give :verbose => false to not log the status.

Examples

  template "README", "doc/README"

  template "doc/README"

Run a thor command. A hash of options can be given and it‘s converted to switches.

Parameters

task<String>:the task to be invoked
args<Array>:arguments to the task
config<Hash>:give :verbose => false to not log the status. Other options are given as parameter to Thor.

Examples

  thor :install, "http://gist.github.com/103208"
  #=> thor install http://gist.github.com/103208

  thor :list, :all => true, :substring => 'rails'
  #=> thor list --all --substring=rails

[Validate]