- Inheritance
- < Rails::Generator::Commands::Base < DelegateClass(Rails::Generator::Base)
Create is the premier generator command. It copies files, creates directories, renders templates, and more.
Constants
Name | Description | |
---|---|---|
SYNONYM_LOOKUP_URI | = "http://wordnet.princeton.edu/perl/webwn?s=%s" |
Methods
Instance
Visibility | Signature |
---|---|
public | class_collisions (*class_names) |
public | complex_template (relative_source, relative_destination, template_options = {}) |
public | directory (relative_path) |
public | file (relative_source, relative_destination, file_options = {}, &block) |
public | identical? (source, destination) {|sf| ...} |
public | migration_template (relative_source, relative_destination, template_options = {}) |
public | readme (*relative_sources) |
public | route_resources (*resources) |
public | template (relative_source, relative_destination, template_options = {}) |
Instance Method Detail
class_collisions(*class_names)
Check whether the given class names are already taken by Ruby or Rails. In the future, expand to check other namespaces such as the rest of the user‘s app.
complex_template(relative_source, relative_destination, template_options = {})
directory(relative_path)
file(relative_source, relative_destination, file_options = {}, &block)
Copy a file from source to destination with collision checking.
The file_options hash accepts :chmod and :shebang and :collision options. :chmod sets the permissions of the destination file:
file 'config/empty.log', 'log/test.log', :chmod => 0664
:shebang sets the #!/usr/bin/ruby line for scripts
file 'bin/generate.rb', 'script/generate', :chmod => 0755, :shebang => '/usr/bin/env ruby'
:collision sets the collision option only for the destination file:
file 'settings/server.yml', 'config/server.yml', :collision => :skip
Collisions are handled by checking whether the destination file exists and either skipping the file, forcing overwrite, or asking the user what to do.
identical?(source, destination) {|sf| ...}
Checks if the source and the destination file are identical. If passed a block then the source file is a template that needs to first be evaluated before being compared to the destination.
migration_template(relative_source, relative_destination, template_options = {})
When creating a migration, it knows to find the first available file in db/migrate and use the migration.rb template.
readme(*relative_sources)
Display a README.
route_resources(*resources)
template(relative_source, relative_destination, template_options = {})
Generate a file for a Rails application using an ERuby template. Looks up and evaluates a template by name and writes the result.
The ERB template uses explicit trim mode to best control the proliferation of whitespace in generated code. <%- trims leading whitespace; -%> trims trailing whitespace including one newline.
A hash of template options may be passed as the last argument. The options accepted by the file are accepted as well as :assigns, a hash of variable bindings. Example:
template 'foo', 'bar', :assigns => { :action => 'view' }
Template is implemented in terms of file. It calls file with a block which takes a file handle and returns its rendered contents.