diff --git a/.gitignore b/.gitignore index 5fff1d9..edaf6dc 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ pkg +.DS_Store \ No newline at end of file diff --git a/lib/generators/timeline_fu/USAGE b/lib/generators/timeline_fu/USAGE new file mode 100644 index 0000000..87e925d --- /dev/null +++ b/lib/generators/timeline_fu/USAGE @@ -0,0 +1,2 @@ +Generates both the TimelineEvent class and the migration to create its table. The table will have subject, actor and secondary actor as polymorphic associations. +The use of this generator is optional. See README for more details. diff --git a/lib/generators/timeline_fu/timeline_fu_generator.rb b/lib/generators/timeline_fu/timeline_fu_generator.rb new file mode 100644 index 0000000..64ca691 --- /dev/null +++ b/lib/generators/timeline_fu/timeline_fu_generator.rb @@ -0,0 +1,21 @@ +require 'rails/generators' +require 'rails/generators/migration' + +class TimelineFuGenerator < Rails::Generators::Base + include Rails::Generators::Migration + source_root File.expand_path(File.join('..', '..', '..', 'generators', 'timeline_fu', 'templates'), File.dirname(__FILE__)) + + + def self.next_migration_number(dirname) + if ActiveRecord::Base.timestamped_migrations + Time.now.utc.strftime("%Y%m%d%H%M%S") + else + "%.3d" % (current_migration_number(dirname) + 1) + end + end + + def create_migration_file + copy_file 'model.rb', 'app/models/timeline_event.rb' + migration_template 'migration.rb', 'db/migrate/create_timeline_events.rb' + end +end