Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add a generator for db migrations

  • Loading branch information...
commit 4d5300b11cfb6bd5e78e33886564791a45c8e8cd 1 parent 7a3e598
@obrie obrie authored
View
1  CHANGELOG.rdoc
@@ -1,5 +1,6 @@
== master
+* Add a generator for db migrations
* Release gems via rake-gemcutter instead of rubyforge
== 0.3.0 / 2009-04-30
View
11 README.rdoc
@@ -32,6 +32,17 @@ how they are persisted.
Note that this is a reference implementation and, most likely, should be
modified for your own usage.
+=== Installation
+
++has_ratings+ requires additional database tables to work. You can generate
+a migration for these tables like so:
+
+ script/generate has_ratings
+
+Then simply migrate your database:
+
+ rake db:migrate
+
=== Example
user = User.find(1)
View
2  Rakefile
@@ -11,7 +11,7 @@ spec = Gem::Specification.new do |s|
s.summary = 'Demonstrates a reference implementation for handling ratings in ActiveRecord'
s.description = s.summary
- s.files = FileList['{app,assets,db,lib,test}/**/*'] + %w(CHANGELOG.rdoc init.rb LICENSE Rakefile README.rdoc) - FileList['test/app_root/{log,log/*,script,script/*}']
+ s.files = FileList['{app,assets,generators,lib,test}/**/*'] + %w(CHANGELOG.rdoc init.rb LICENSE Rakefile README.rdoc) - FileList['test/app_root/{log,log/*,script,script/*}']
s.require_path = 'lib'
s.has_rdoc = true
s.test_files = Dir['test/**/*_test.rb']
View
5 generators/has_ratings/USAGE
@@ -0,0 +1,5 @@
+Usage:
+
+ script/generate has_ratings
+
+This will create migrations that will add the proper tables to store ratings.
View
9 generators/has_ratings/has_ratings_generator.rb
@@ -0,0 +1,9 @@
+class HasRatingsGenerator < Rails::Generator::Base
+ def manifest
+ record do |m|
+ m.migration_template '001_create_rating_values.rb', 'db/migrate', :migration_file_name => 'create_rating_values'
+ m.sleep 1
+ m.migration_template '002_create_ratings.rb', 'db/migrate', :migration_file_name => 'create_ratings'
+ end
+ end
+end
View
0  db/migrate/001_create_rating_values.rb → ...has_ratings/templates/001_create_rating_values.rb
File renamed without changes
View
0  db/migrate/002_create_ratings.rb → ...ators/has_ratings/templates/002_create_ratings.rb
File renamed without changes
View
4 test/app_root/db/migrate/003_migrate_has_ratings_to_version_2.rb
@@ -1,12 +1,12 @@
class MigrateHasRatingsToVersion2 < ActiveRecord::Migration
def self.up
- ActiveRecord::Migrator.new(:up, "#{Rails.root}/../../db/migrate", 0).migrations.each do |migration|
+ ActiveRecord::Migrator.new(:up, "#{Rails.root}/../../generators/has_ratings/templates", 0).migrations.each do |migration|
migration.migrate(:up)
end
end
def self.down
- ActiveRecord::Migrator.new(:up, "#{Rails.root}/../../db/migrate", 0).migrations.each do |migration|
+ ActiveRecord::Migrator.new(:down, "#{Rails.root}/../../generators/has_ratings/templates", 0).migrations.each do |migration|
migration.migrate(:down)
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.