Changeset 3098
- Timestamp:
- 11/20/05 04:21:06 (3 years ago)
- Files:
-
- trunk/railties/CHANGELOG (modified) (1 diff)
- trunk/railties/lib/rails_generator/commands.rb (modified) (5 diffs)
- trunk/railties/lib/rails_generator/generators/components/migration/migration_generator.rb (modified) (1 diff)
- trunk/railties/lib/rails_generator/generators/components/session_migration (added)
- trunk/railties/lib/rails_generator/generators/components/session_migration/session_migration_generator.rb (added)
- trunk/railties/lib/rails_generator/generators/components/session_migration/templates (added)
- trunk/railties/lib/rails_generator/generators/components/session_migration/templates/migration.rb (added)
- trunk/railties/lib/rails_generator/generators/components/session_migration/USAGE (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/railties/CHANGELOG
r3091 r3098 1 1 *SVN* 2 3 * Introducing the session_migration generator. Creates an add_session_table migration. #2958 [Rick Olson] 2 4 3 5 * Update to Prototype 1.4.0_rc4. Closes #2943 (old Array.prototype.reverse behavior can be obtained by passing false as an argument). [Sam Stephenson] trunk/railties/lib/rails_generator/commands.rb
r3081 r3098 56 56 end 57 57 58 protected 59 def existing_migrations(file_name) 60 Dir.glob("db/migrate/[0-9]*_#{file_name}.rb") 61 end 62 63 def migration_exists?(file_name) 64 not existing_migrations(file_name).empty? 65 end 66 67 def current_migration_number 68 Dir.glob('db/migrate/[0-9]*.rb').inject(0) do |max, file_path| 69 n = File.basename(file_path).split('_', 2).first.to_i 70 if n > max then n else max end 71 end 72 end 73 74 def next_migration_number 75 current_migration_number + 1 76 end 77 78 def next_migration_string(padding = 3) 79 "%.#{padding}d" % next_migration_number 80 end 81 58 82 private 59 83 # Ask the user interactively whether to force collision. … … 85 109 end_mark = template_part_mark(template_options[:end_mark], template_options[:mark_id]) 86 110 begin_mark + rendered_part + end_mark 87 end88 89 def template_part_mark(name, id)90 "<!--[#{name}:#{id}]-->\n"111 end 112 113 def template_part_mark(name, id) 114 "<!--[#{name}:#{id}]-->\n" 91 115 end 92 116 end … … 278 302 puts File.read(source_path(relative_source)) unless options[:pretend] 279 303 end 304 end 305 306 # When creating a migration, it knows to find the first available file in db/migrate and use the migration.rb template. 307 def migration_template(relative_source, relative_destination, template_options = {}) 308 raise "Another migration is already named #{file_name}: #{existing_migrations(file_name).first}" if migration_exists?(file_name) 309 template(relative_source, "#{relative_destination}/#{next_migration_string}_#{file_name}.rb", template_options) 280 310 end 281 311 … … 386 416 # nothing should be done here 387 417 end 418 419 # When deleting a migration, it knows to delete every file named "[0-9]*_#{file_name}". 420 def migration_template(relative_source, relative_destination, template_options = {}) 421 raise "There is no migration named #{file_name}" unless migration_exists?(file_name) 422 existing_migrations(file_name).each do |file_path| 423 file(relative_source, file_path, template_options) 424 end 425 end 388 426 end 389 427 … … 417 455 def readme(*args) 418 456 logger.readme args.join(', ') 457 end 458 459 def migration_template(relative_source, relative_destination, options = {}) 460 logger.migration_template file_name 419 461 end 420 462 end trunk/railties/lib/rails_generator/generators/components/migration/migration_generator.rb
r2799 r3098 6 6 end 7 7 end 8 9 protected10 def existing_migrations(file_name)11 Dir.glob("db/migrate/[0-9]*_#{file_name}.rb")12 end13 14 def migration_exists?(file_name)15 not existing_migrations(file_name).empty?16 end17 18 def current_migration_number19 Dir.glob('db/migrate/[0-9]*.rb').inject(0) do |max, file_path|20 n = File.basename(file_path).split('_', 2).first.to_i21 if n > max then n else max end22 end23 end24 25 def next_migration_number26 current_migration_number + 127 end28 29 def next_migration_string(padding = 3)30 "%.#{padding}d" % next_migration_number31 end32 8 end 33 34 module Rails::Generator::Commands35 # When creating, it knows to find the first available file in db/migrate and use the migration.rb template.36 class Create37 def migration_template(relative_source, relative_destination, template_options = {})38 raise "Another migration is already named #{file_name}: #{existing_migrations(file_name).first}" if migration_exists?(file_name)39 template(relative_source, "#{relative_destination}/#{next_migration_string}_#{file_name}.rb", template_options)40 end41 end42 43 # When deleting, it knows to delete every file named "[0-9]*_#{file_name}".44 class Destroy45 def migration_template(relative_source, relative_destination, template_options = {})46 raise "There is no migration named #{file_name}" unless migration_exists?(file_name)47 existing_migrations(file_name).each do |file_path|48 file(relative_source, file_path, template_options)49 end50 end51 end52 53 class List54 def migration_template(relative_source, relative_destination, options = {})55 logger.migration_template file_name56 end57 end58 end