Class: RubiGen::Commands::Create

Class | RubiGen::Commands::Create
In: | lib/rubigen/commands.rb
Parent: | Base

Create is the premier generator command. It copies files, creates directories, renders templates, and more.

### Methods

class_collisions complex_template directory file file_copy_each folder identical? migration_template readme route_resources template template_copy_each write_manifest

### Constants

SYNONYM_LOOKUP_URI | = | "http://wordnet.princeton.edu/perl/webwn?s=%s"

### Public Instance methods

class_collisions(*class_names)

Check whether the given class names are already taken. 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)

Create a directory including any missing parent directories. Always skips directories which exist.

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.

file_copy_each(files, path=nil, options = {})
folder(template_path, path=nil, options = {})
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 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.

template_copy_each(files, path = nil, options = {})
write_manifest(relative_destination)

[Validate]