Skip to content
This repository has been archived by the owner on Dec 30, 2019. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
added generator for model and migration to use instead the command dump
  • Loading branch information
adzap committed Jun 23, 2009
1 parent 6fdde2f commit 5866745
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
25 changes: 25 additions & 0 deletions generators/ar_mailer/ar_mailer_generator.rb
@@ -0,0 +1,25 @@
class ArMailerGenerator < Rails::Generator::NamedBase

def initialize(runtime_args, runtime_options = {})
runtime_args.unshift('Email') if runtime_args.empty?
super
end

def manifest
record do |m|
m.class_collisions class_name

m.template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb")

m.migration_template 'migration.rb', 'db/migrate', :assigns => {
:migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}"
}, :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}"
end
end

protected
def banner
"Usage: #{$0} #{spec.name} EmailModelName (default: Email)"
end

end
15 changes: 15 additions & 0 deletions generators/ar_mailer/templates/migration.rb
@@ -0,0 +1,15 @@
class <%= migration_name %> < ActiveRecord::Migration
def self.up
create_table :<%= table_name %> do |t|
t.column :from, :string
t.column :to, :string
t.column :last_send_attempt, :integer, :default => 0
t.column :mail, :text
t.column :created_on, :datetime
end
end

def self.down
drop_table :<%= table_name %>
end
end
2 changes: 2 additions & 0 deletions generators/ar_mailer/templates/model.rb
@@ -0,0 +1,2 @@
class <%= class_name %> < ActiveRecord::Base
end

0 comments on commit 5866745

Please sign in to comment.