scaffold_plus 1.7.4 → 1.7.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1076ab26d1d0f4d8b72e02f9cb1bbdd04b641580
4
- data.tar.gz: 199d61b5ceaaef8e3387894ce4bea977c67a6be5
3
+ metadata.gz: dbfbc1604c1f6d200fbd60cc086e9dd1276512ea
4
+ data.tar.gz: 533ec872a540106525ea897c3538e16cf0135019
5
5
  SHA512:
6
- metadata.gz: b59cb120b626bfe7ed9bc210522eb0a1b8a13e202125b9c2d6d13b611ba18f0d32b5359bb7e30bf27d8da57fac751783add28c28ded8d6955b488a59b070d099
7
- data.tar.gz: 0d8ec2256a793223eaf3276ddeb5135c7b902eefb2bc9548b5d00f084647564de4270b9f58d97edfbd7fc6cc29bf0e973e3d9d973f460b792ec96b1f252ea38f
6
+ metadata.gz: 9e8e4e1a13f2e736099adf843d0eaf8bfbe57d2ab712abd221a9bcbf952c4f77d4d2065079a9237662069e2bec37855efe6fa9310c441d0d16bb749024c56874
7
+ data.tar.gz: 8c7c02bc8ca4ce04a9414cfe7080f10bc821b000e520ee93a5fed40bb5f23b399e1d9313949f84b1c7ea03b58b4c55a6f68422bb47232863032ee70a85b9e3e6
@@ -12,6 +12,8 @@ module ScaffoldPlus
12
12
  desc: 'Can be destroy, delete, or restrict'
13
13
  class_option :nested, type: :array, banner: 'attribute [...]',
14
14
  desc: 'Add accepts_nested_attributes_for (incl. whitelisting)'
15
+ class_option :route, type: :boolean, default: false,
16
+ desc: 'Add a nested route and update CHILD controller'
15
17
  class_option :foreign_key, type: :string,
16
18
  desc: 'Set the name of the foreign key directly'
17
19
  class_option :inverse, type: :boolean, default: false,
@@ -27,17 +29,27 @@ module ScaffoldPlus
27
29
  class_option :after, type: :array,
28
30
  desc: 'Add a line after generated text in models'
29
31
  source_root File.expand_path('../templates', __FILE__)
30
-
32
+
31
33
  def add_migration
32
34
  return unless options.migration?
33
35
  migration_template 'child_migration.rb', "db/migrate/#{migration_name}.rb"
34
36
  end
35
-
37
+
36
38
  def add_counter
37
39
  return unless options.counter?
38
40
  migration_template 'counter_migration.rb', "db/migrate/#{counter_migration}.rb"
39
41
  end
40
-
42
+
43
+ def add_to_route
44
+ return unless options.route?
45
+ gsub_file "config/routes.rb", /^ resources :#{table_name} do$/ do |match|
46
+ match << "\n resources :#{children}"
47
+ end
48
+ gsub_file "config/routes.rb", /^ resources :#{table_name}$/ do |match|
49
+ match << " do\n resources :#{children}\n end"
50
+ end
51
+ end
52
+
41
53
  def add_to_models
42
54
  inject_into_class "app/models/#{name}.rb", class_name do
43
55
  text = before_array.include?(name) ? "\n" : ""
@@ -51,7 +63,7 @@ module ScaffoldPlus
51
63
  text << "\n" if after_array.include?(name)
52
64
  text
53
65
  end
54
-
66
+
55
67
  child = children.singularize
56
68
  inject_into_class "app/models/#{child}.rb", child.camelize do
57
69
  text = before_array.include?(child) ? "\n" : ""
@@ -66,7 +78,7 @@ module ScaffoldPlus
66
78
  text
67
79
  end
68
80
  end
69
-
81
+
70
82
  def add_to_permit
71
83
  return unless options[:nested].present?
72
84
  list = options[:nested].map{|n| ":#{n}"}.join(', ')
@@ -76,17 +88,34 @@ module ScaffoldPlus
76
88
  # Special case: no previous permit
77
89
  gsub_file file, /^(\s*params)\[:#{name}\]$/, "\\1.require(:#{name}).permit(#{text})"
78
90
  end
79
-
91
+
92
+ def update_child_controller_and_view
93
+ return unless options.route?
94
+ child = children.singularize
95
+ file = "app/controllers/#{children}_controller.rb"
96
+ gsub_file file, /GET .#{children}.new$/ do |match|
97
+ match = "GET /#{table_name}/:id/#{children}/new"
98
+ end
99
+ gsub_file file, /^ @#{child} = #{child.camelize}.new$/ do |match|
100
+ match = " @#{name} = #{class_name}.find(params[:#{name}_id])\n" +
101
+ " @#{child} = @#{name}.#{children}.build"
102
+ end
103
+ file = "app/views/#{children}/_form.html.erb"
104
+ gsub_file file, /form_for\(@#{child}/ do |match|
105
+ match = "form_for([@#{name}, @#{child}]"
106
+ end
107
+ end
108
+
80
109
  protected
81
-
110
+
82
111
  def before_array
83
112
  options['before'] || []
84
113
  end
85
-
114
+
86
115
  def after_array
87
116
  options['after'] || []
88
117
  end
89
-
118
+
90
119
  def dependent
91
120
  if options[:dependent].present? && options[:dependent] == "restrict"
92
121
  "restrict_with_exception"
@@ -94,15 +123,11 @@ module ScaffoldPlus
94
123
  options[:dependent]
95
124
  end
96
125
  end
97
-
126
+
98
127
  def migration_name
99
128
  "add_#{name}_id_to_#{children}"
100
129
  end
101
-
102
- def create_index?
103
- options[:index]
104
- end
105
-
130
+
106
131
  def counter_migration
107
132
  "add_#{children}_count_to_#{table_name}"
108
133
  end
@@ -1,7 +1,7 @@
1
1
  class <%= migration_name.camelize %> < ActiveRecord::Migration
2
2
  def change
3
3
  add_column :<%= children %>, :<%= name %>_id, :integer
4
- <%- if create_index? -%>
4
+ <%- if options.index? -%>
5
5
  add_index :<%= children %>, :<%= name %>_id
6
6
  <%- end -%>
7
7
  end
@@ -1,3 +1,3 @@
1
1
  module ScaffoldPlus
2
- VERSION = "1.7.4"
2
+ VERSION = "1.7.5"
3
3
  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.7.4
4
+ version: 1.7.5
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-24 00:00:00.000000000 Z
11
+ date: 2014-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord