class Grails::Generate

Public Instance Methods

controller(name) click to toggle source
# File lib/commands.rb, line 36
def controller(name)
  controller_path = File.join(project_root, "app/controllers/#{file.pluralize.underscore}_controlller.rb")
  controller_name = "#{name.pluralize.camelcase}Controller"
  view_dir = File.join(project_root, "app/views/#{file.pluralize.underscore}")
  raise "Controller already exists" if File.exist?(controller_path)

  File.open(controller_path, "w") do |file|
    file.write("class #{controller_name} < ApplicationController\n")
    file.write("end")
  end
  Dir.mkdir(view_dir) unless Dir.exist?(view_dir)
  puts "New controller file #{name} can be found at #{controller_path}"
end
migration(name) click to toggle source
# File lib/commands.rb, line 11
def migration(name)
  file_name = name
  timestamp = Time.now.to_i
  path = File.join(project_root, "db/migrations/#{timestamp}_#{name}.sql")
  File.new(path, "w")

  puts "New migration file #{name} can be found at #{path}"
end
model(name) click to toggle source
# File lib/commands.rb, line 21
def model(name)
  path = File.join(project_root, "app/models/#{name.underscore}.rb")
  raise "Model already exists" if File.exist?(path)

  File.open(path, "w") do |file|
    file.write("class #{name.camelcase} < GrailedORM::Base\n")
    file.write("   self.finalize!\n")
    file.write("end\n")
  end

  migration(name)
  puts "New migration file #{name} can be found at #{path}"
end