Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added generator for model and migration to use instead the command dump

  • Loading branch information...
commit 5866745e4e6a3e859e5e362f2aeb28ff09d0ca8c 1 parent 6fdde2f
@adzap authored
View
25 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
View
15 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
View
2  generators/ar_mailer/templates/model.rb
@@ -0,0 +1,2 @@
+class <%= class_name %> < ActiveRecord::Base
+end
Please sign in to comment.
Something went wrong with that request. Please try again.