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

Constants

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

Public Instance methods

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.

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

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.

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.

When creating a migration, it knows to find the first available file in db/migrate and use the migration.rb template.

Display a README.

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.

[Validate]