Sha256: f32c83998d567dac94857702c0a3fed6794e92fa11a8f99e703b1f1b8b884342
Contents?: true
Size: 1.41 KB
Versions: 29
Compression:
Stored size: 1.41 KB
Contents
class HistoryModelGenerator < Rails::Generator::NamedBase default_options :skip_migration => false def manifest record do |m| # # Check for class naming collisions. m.class_collisions class_path, "#{class_name}History" # m.class_collisions class_path, "#{class_name}HistoryTest" # # # Model, test, and fixture directories. m.directory File.join('app/models', class_path) # m.directory File.join('test/unit', class_path) # m.directory File.join('test/fixtures', class_path) # # # Model class, unit test, and fixtures. m.template 'model.rb', File.join('app/models', class_path, "#{file_name}_history.rb") # m.template 'unit_test.rb', File.join('test/unit', class_path, "#{file_name}_history_test.rb") # m.template 'fixtures.yml', File.join('test/fixtures', class_path, "#{table_name}_history.yml") m.dependency 'model', ["#{class_name}History"], :collision => :skip, :skip_migration => true unless options[:skip_migration] m.dependency 'history_migration', [class_name], :collision => :skip, :skip_migration => true end end end protected def banner "Usage: #{$0} generate ModelName" end def add_options!(opt) opt.separator '' opt.separator 'Options:' opt.on("--skip-migration", "Don't generate a migration file for this history model") { |v| options[:skip_migration] = v } end end
Version data entries
29 entries across 20 versions & 1 rubygems