behavior | [RW] | |
output_buffer | [RW] |
Extends initializer to add more configuration options.
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. |
Append text to a file. Since it depends on insert_into_file, it‘s reversible.
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. |
append_to_file 'config/environments/test.rb', 'config.gem "rspec"' append_to_file 'config/environments/test.rb' do 'config.gem "rspec"' end
Loads an external file and execute it in the instance binding.
path<String>: | The path to the file to execute. Can be a web address or a relative path from the source root. |
apply "http://gist.github.com/103208" apply "recipes/jquery.rb"
Changes the mode of the given file or directory.
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. |
chmod "script/*", 0755
Comment all lines matching a given regex. It will leave the space which existed before the beginning of the line in tact and will insert a single space after the comment hash.
path<String>: | path of the file to be changed |
flag<Regexp|String>: | the regexp or string used to decide which lines to comment |
config<Hash>: | give :verbose => false to not log the status. |
comment_lines 'config/initializers/session_store.rb', /cookie_store/
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.
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. |
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.
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. |
create_file "lib/fun_party.rb" do hostname = ask("What is the virtual hostname I should use?") "vhost.name = #{hostname}" end create_file "config/apache.conf", "your apache config"
Create a new file relative to the destination root from the given source.
destination<String>: | the relative path to the destination root. |
source<String|NilClass>: | the relative path to the source root. |
config<Hash>: | give :verbose => false to not log the status. |
:: give :symbolic => false for hard link.
create_link "config/apache.conf", "/etc/apache.conf"
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. If any file name is wrapped within % signs, the text within the % signs will be executed as a method and replaced with the returned value. 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` method returns the value "blog"):
doc/ components/ README rdoc.rb blog.rb
Encoded path note: Since Thor internals use Object#respond_to? to check if it can expand %something%, this `something` should be a public method in the class calling directory. If a method is private, Thor stack raises PrivateMethodEncodedError.
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. |
directory "doc" directory "doc", "docs", :recursive => false
Creates an empty directory.
destination<String>: | the relative path to the destination root. |
config<Hash>: | give :verbose => false to not log the status. |
empty_directory "doc"
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.
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. |
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.
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. |
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
Injects text right after the class definition. Since it depends on insert_into_file, it‘s reversible.
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. |
inject_into_class "app/controllers/application_controller.rb", ApplicationController, " 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.
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. |
insert_into_file "config/environment.rb", "config.gem :thor", :after => "Rails::Initializer.run do |config|\n" insert_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.
dir<String>: | the directory to move to. |
config<Hash>: | give :verbose => true to log and use padding. |
Links 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.
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. |
link_file "README", "doc/README" link_file "doc/README"
Prepend text to a file. Since it depends on insert_into_file, it‘s reversible.
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. |
prepend_to_file 'config/environments/test.rb', 'config.gem "rspec"' prepend_to_file 'config/environments/test.rb' do 'config.gem "rspec"' end
Removes a file at the given location.
path<String>: | path of the file to be changed |
config<Hash>: | give :verbose => false to not log the status. |
remove_file 'README' remove_file 'app/controllers/application_controller.rb'
Executes a command returning the contents of the command.
command<String>: | the command to be executed. |
config<Hash>: | give :verbose => false to not log the status, :capture => true to hide to output. Specify :with to append an executable to command executation. |
inside('vendor') do run('ln -s ~/edge rails') end
Executes a ruby script (taking into account WIN32 platform quirks).
command<String>: | the command to be executed. |
config<Hash>: | give :verbose => false to not log the status. |
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.
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. |
template "README", "doc/README" template "doc/README"
Run a thor command. A hash of options can be given and it‘s converted to switches.
task<String>: | the task to be invoked |
args<Array>: | arguments to the task |
config<Hash>: | give :verbose => false to not log the status, :capture => true to hide to output. Other options are given as parameter to Thor. |
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
Uncomment all lines matching a given regex. It will leave the space which existed before the comment hash in tact but will remove any spacing between the comment hash and the beginning of the line.
path<String>: | path of the file to be changed |
flag<Regexp|String>: | the regexp or string used to decide which lines to uncomment |
config<Hash>: | give :verbose => false to not log the status. |
uncomment_lines 'config/initializers/session_store.rb', /active_record/