scaffold_plus 2.1.2 → 2.1.3

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: 450cf4b87abe4a2a86ad00fe8b053a71c6fba8c7
4
- data.tar.gz: 74a215ecd8504a343c96ce597d8135208b0c0d36
3
+ metadata.gz: 8708dc46850e0461defb7300d245701316cf8ebb
4
+ data.tar.gz: 890e0dd4a202e7266e140a8d260ac02dd85ed6f9
5
5
  SHA512:
6
- metadata.gz: 398ecfa0f85c0d931fabc4a844e1864a10851fe758d97e6478d270e3d29758c38f1da2c212ace792473d0edb462f97a1f498b6ed41d1d5f09f786605b0c59e24
7
- data.tar.gz: d8af2ce1c3b5ed8455c80edd10d0bd0da937a82eb44f649ab10518ed24a39693589596b4efecf22868036d37b1d3496c2aba6dc9f0109c37d0d38aed4d29e0d3
6
+ metadata.gz: c87225f56c51195d16dd58a3851d36a358a1d93559adf4b56de652a36e39ffe634bfa3d2fff09c70d001b1bfdab1784136f85f98abd1ccee458623d4b9dbe4f7
7
+ data.tar.gz: 3964f33ce1a8c2a227cc3c5639e6310e66c1289f2196ca80e3aeb44387c9ea6f9efd4fcfb25f888c7b94786931b9d27bba6c43e1d220195aa3829fd134cdf9eb
@@ -49,7 +49,7 @@ module ScaffoldPlus
49
49
  protected
50
50
 
51
51
  def migration_name
52
- "add_ancestry_to_#{table_name}"
52
+ "add_#{column}_to_#{table_name}"
53
53
  end
54
54
  end
55
55
  end
@@ -60,7 +60,7 @@ module ScaffoldPlus
60
60
  text << ", dependent: :#{dependent}" if options.dependent.present?
61
61
  text << "\n"
62
62
  if options.nested.present?
63
- text << " accepts_nested_attributes_for :#{children}\n"
63
+ text << " accepts_nested_attributes_for :#{children}, allow_destroy: true, reject_if: :all_blank\n"
64
64
  end
65
65
  text << "\n" if after_array.include?(name)
66
66
  text
@@ -50,9 +50,9 @@ module ScaffoldPlus
50
50
  text = before_array.include?(name) ? "\n" : ""
51
51
  text << " has_one :#{child}"
52
52
  text << ", inverse_of: :#{name}" if options.inverse?
53
- text << ", dependent: :#{dependent}" if options.dependent
53
+ text << ", dependent: :#{dependent}" if options.dependent.present?
54
54
  text << "\n"
55
- if options.nested
55
+ if options.nested.present?
56
56
  text << " accepts_nested_attributes_for :#{child}, allow_destroy: true\n"
57
57
  end
58
58
  text << "\n" if after_array.include?(name)
@@ -77,6 +77,7 @@ module ScaffoldPlus
77
77
  list = options.nested.map{|n| ":#{n}"}.join(', ')
78
78
  text = "#{child}_attributes: [ #{list} ]"
79
79
  file = "app/controllers/#{table_name}_controller.rb"
80
+ return unless File.exist?(file)
80
81
  gsub_file file, /(permit\(.*)\)/, "\\1, #{text})"
81
82
  # Special case: no previous permit
82
83
  gsub_file file, /^(\s*params)\[:#{name}\]$/, "\\1.require(:#{name}).permit(#{text})"
@@ -86,6 +87,7 @@ module ScaffoldPlus
86
87
  return unless options.permit?
87
88
  text = ":#{name}_id"
88
89
  file = "app/controllers/#{child.pluralize}_controller.rb"
90
+ return unless File.exist?(file)
89
91
  gsub_file file, /(permit\(.*)\)/, "\\1, #{text})"
90
92
  # Special case: no previous permit
91
93
  gsub_file file, /^(\s*params)\[:#{name}\]$/, "\\1.require(:#{name}).permit(#{text})"
@@ -95,16 +97,20 @@ module ScaffoldPlus
95
97
  return unless options.route?
96
98
  children = child.pluralize
97
99
  file = "app/controllers/#{children}_controller.rb"
98
- gsub_file file, /GET .#{children}.new$/ do |match|
99
- match = "GET /#{table_name}/:id/#{children}/new"
100
- end
101
- gsub_file file, /^ @#{child} = #{child.camelize}.new$/ do |match|
102
- match = " @#{name} = #{class_name}.find(params[:#{name}_id])\n" +
103
- " @#{child} = @#{name}.#{children}.build"
100
+ if File.exist?(file)
101
+ gsub_file file, /GET .#{children}.new$/ do |match|
102
+ match = "GET /#{table_name}/:id/#{children}/new"
103
+ end
104
+ gsub_file file, /^ @#{child} = #{child.camelize}.new$/ do |match|
105
+ match = " @#{name} = #{class_name}.find(params[:#{name}_id])\n" +
106
+ " @#{child} = @#{name}.#{children}.build"
107
+ end
104
108
  end
105
109
  file = "app/views/#{children}/_form.html.erb"
106
- gsub_file file, /form_for\(@#{child}/ do |match|
107
- match = "form_for([@#{name}, @#{child}]"
110
+ if File.exist?(file)
111
+ gsub_file file, /form_for\(@#{child}/ do |match|
112
+ match = "form_for([@#{name}, @#{child}]"
113
+ end
108
114
  end
109
115
  end
110
116
 
@@ -119,7 +125,7 @@ module ScaffoldPlus
119
125
  end
120
126
 
121
127
  def dependent
122
- if options.dependent && options.dependent == "restrict"
128
+ if options.dependent.present? && options.dependent == "restrict"
123
129
  "restrict_with_exception"
124
130
  else
125
131
  options.dependent
@@ -132,3 +138,5 @@ module ScaffoldPlus
132
138
  end
133
139
  end
134
140
  end
141
+
142
+ # vim: set expandtab softtabstop=2 shiftwidth=2 autoindent :
@@ -1,3 +1,3 @@
1
1
  module ScaffoldPlus
2
- VERSION = "2.1.2"
2
+ VERSION = "2.1.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scaffold_plus
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2
4
+ version: 2.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Volker Wiegand