blob: acf41e07df5e75c9d3477f997ad36dadf2eb1282 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
class MigrationGenerator < Rails::Generator::NamedBase
def manifest
record do |m|
m.migration_template 'migration.rb', 'db/migrate', :assigns => get_local_assigns
end
end
private
def get_local_assigns
returning(assigns = {}) do
if class_name.underscore =~ /^(add|remove)_.*_(?:to|from)_(.*)/
assigns[:migration_action] = $1
assigns[:table_name] = $2.pluralize
else
assigns[:attributes] = []
end
end
end
end
|