scaffold_plus 1.7.14 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -0
- data/lib/generators/scaffold_plus/geodesic/geodesic_generator.rb +1 -1
- data/lib/generators/scaffold_plus/migration/migration_generator.rb +77 -0
- data/lib/generators/scaffold_plus/migration/templates/change_migration.rb +5 -0
- data/lib/scaffold_plus/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b36d5e911b460ba3b91084f076a0c9905aab19d
|
4
|
+
data.tar.gz: fdcefa09351b7cfac5a43e460ea62f38c5626bb8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a7a18ef9e70632da0d2bdf1c3698ee20a0579f867c5e7a59d752a8021638e2a42e4622bba1848237be31a754f1671f9950bb590ffa09f5b27fe538b260c6e13
|
7
|
+
data.tar.gz: 5f14a2d39d0e5c38d0d94adf7c34bb6f6c58f596ea3d5fe308a18fcd2b9d0b1fd5fe5dae91ebb91541f982bd858812b15ebbcbfa581f4988a07933922cf16f7c
|
data/README.md
CHANGED
@@ -18,6 +18,15 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
+
### Add migrations to change tables and columns
|
22
|
+
rails generate scaffold_plus:migration table --remove column [...]
|
23
|
+
rails generate scaffold_plus:migration table --rename old:new [...]
|
24
|
+
rails generate scaffold_plus:migration table --change column:type [...]
|
25
|
+
rails generate scaffold_plus:migration table --not_null column [...]
|
26
|
+
rails generate scaffold_plus:migration table --set_default column:value [...]
|
27
|
+
|
28
|
+
This helper creates migrations for some 'ALTER TABLE' statements.
|
29
|
+
|
21
30
|
### Add regular one-to-many association (has_many / belongs_to)
|
22
31
|
rails generate scaffold_plus:has_many
|
23
32
|
|
@@ -62,7 +62,7 @@ module ScaffoldPlus
|
|
62
62
|
|
63
63
|
def update_controller
|
64
64
|
return unless options.permit?
|
65
|
-
text = ":#{options.latitude}, :#{options.
|
65
|
+
text = ":#{options.latitude}, :#{options.longitude}"
|
66
66
|
text << ", :address, :country" if options.address?
|
67
67
|
file = "app/controllers/#{table_name}_controller.rb"
|
68
68
|
gsub_file file, /(permit\(.*)\)/, "\\1, #{text})"
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'rails/generators/active_record'
|
2
|
+
|
3
|
+
module ScaffoldPlus
|
4
|
+
module Generators
|
5
|
+
class MigrationGenerator < ActiveRecord::Generators::Base
|
6
|
+
desc "Generate additional ALTER TABLE migrations"
|
7
|
+
argument :name, type: :string,
|
8
|
+
desc: 'The resource to be changed'
|
9
|
+
class_option :remove, type: :array, banner: 'column [...]',
|
10
|
+
desc: 'Columns that shall be removed'
|
11
|
+
class_option :rename, type: :array, banner: 'old_name:new_name [...]',
|
12
|
+
desc: 'Columns that shall be renamed'
|
13
|
+
class_option :change, type: :array, banner: 'column:new_type [...]',
|
14
|
+
desc: 'Change column types'
|
15
|
+
class_option :not_null, type: :array, banner: 'column [...]',
|
16
|
+
desc: 'Columns that may mot be NULL'
|
17
|
+
class_option :set_default, type: :array, banner: 'column:value [...]',
|
18
|
+
desc: 'Default values for columns'
|
19
|
+
source_root File.expand_path('../templates', __FILE__)
|
20
|
+
|
21
|
+
def prepare_the_lines
|
22
|
+
@the_lines = []
|
23
|
+
end
|
24
|
+
|
25
|
+
def prepare_change_table
|
26
|
+
return unless options.remove.present? or options.rename.present?
|
27
|
+
@the_lines << " change_table :#{table_name} do |t|"
|
28
|
+
if options.remove.present?
|
29
|
+
options.remove.each do |column|
|
30
|
+
@the_lines << " t.remove :#{column}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
if options.rename.present?
|
34
|
+
options.rename.each do |column|
|
35
|
+
old_name, new_name = column.split(':')
|
36
|
+
@the_lines << " t.rename :#{old_name}, :#{new_name}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
@the_lines << " end"
|
40
|
+
end
|
41
|
+
|
42
|
+
def prepare_change_column
|
43
|
+
return unless options.change.present?
|
44
|
+
options.change.each do |column|
|
45
|
+
column, new_type = column.split(':')
|
46
|
+
@the_lines << " change_column :#{table_name}, :#{column}, :#{new_type}"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def prepare_not_null
|
51
|
+
return unless options.not_null.present?
|
52
|
+
options.not_null.each do |column|
|
53
|
+
@the_lines << " change_column_null :#{table_name}, :#{column}, false"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def prepare_set_default
|
58
|
+
return unless options.set_default.present?
|
59
|
+
options.set_default.each do |column|
|
60
|
+
column, preset = column.split(':')
|
61
|
+
@the_lines << " change_column_default :#{table_name}, :#{column}, #{preset}"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def add_migration
|
66
|
+
return unless @the_lines.any?
|
67
|
+
migration_template "change_migration.rb", "db/migrate/#{migration_name}.rb"
|
68
|
+
end
|
69
|
+
|
70
|
+
protected
|
71
|
+
|
72
|
+
def migration_name
|
73
|
+
"change_#{table_name}"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scaffold_plus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Volker Wiegand
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -103,6 +103,8 @@ files:
|
|
103
103
|
- lib/generators/scaffold_plus/many_to_many/templates/counter_migration.rb
|
104
104
|
- lib/generators/scaffold_plus/many_to_many/templates/many_to_many_migration.rb
|
105
105
|
- lib/generators/scaffold_plus/many_to_many/templates/many_to_many_model.rb
|
106
|
+
- lib/generators/scaffold_plus/migration/migration_generator.rb
|
107
|
+
- lib/generators/scaffold_plus/migration/templates/change_migration.rb
|
106
108
|
- lib/scaffold_plus.rb
|
107
109
|
- lib/scaffold_plus/version.rb
|
108
110
|
- scaffold_plus.gemspec
|