railties 4.2.11.3 → 5.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (180) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +262 -206
  3. data/MIT-LICENSE +20 -0
  4. data/README.rdoc +1 -1
  5. data/{bin → exe}/rails +0 -0
  6. data/lib/rails.rb +19 -1
  7. data/lib/rails/all.rb +10 -9
  8. data/lib/rails/api/task.rb +7 -14
  9. data/lib/rails/{app_rails_loader.rb → app_loader.rb} +4 -3
  10. data/lib/rails/application.rb +31 -41
  11. data/lib/rails/application/bootstrap.rb +1 -14
  12. data/lib/rails/application/configuration.rb +94 -95
  13. data/lib/rails/application/default_middleware_stack.rb +30 -16
  14. data/lib/rails/application/finisher.rb +11 -2
  15. data/lib/rails/application/routes_reloader.rb +1 -3
  16. data/lib/rails/application_controller.rb +1 -1
  17. data/lib/rails/cli.rb +2 -2
  18. data/lib/rails/code_statistics.rb +6 -8
  19. data/lib/rails/code_statistics_calculator.rb +8 -1
  20. data/lib/rails/command.rb +70 -0
  21. data/lib/rails/commands.rb +5 -3
  22. data/lib/rails/commands/commands_tasks.rb +25 -14
  23. data/lib/rails/commands/console.rb +7 -52
  24. data/lib/rails/commands/console_helper.rb +34 -0
  25. data/lib/rails/commands/dbconsole.rb +59 -78
  26. data/lib/rails/commands/dev_cache.rb +21 -0
  27. data/lib/rails/commands/plugin.rb +1 -1
  28. data/lib/rails/commands/rake_proxy.rb +34 -0
  29. data/lib/rails/commands/runner.rb +0 -1
  30. data/lib/rails/commands/server.rb +29 -36
  31. data/lib/rails/commands/test.rb +9 -0
  32. data/lib/rails/configuration.rb +21 -5
  33. data/lib/rails/console/app.rb +5 -0
  34. data/lib/rails/console/helpers.rb +1 -1
  35. data/lib/rails/engine.rb +68 -58
  36. data/lib/rails/engine/commands.rb +4 -2
  37. data/lib/rails/engine/configuration.rb +4 -10
  38. data/lib/rails/gem_version.rb +4 -4
  39. data/lib/rails/generators.rb +30 -7
  40. data/lib/rails/generators/.named_base.rb.swp +0 -0
  41. data/lib/rails/generators/actions.rb +19 -5
  42. data/lib/rails/generators/app_base.rb +65 -45
  43. data/lib/rails/generators/base.rb +6 -6
  44. data/lib/rails/generators/erb/mailer/mailer_generator.rb +5 -8
  45. data/lib/rails/generators/erb/scaffold/templates/_form.html.erb +9 -7
  46. data/lib/rails/generators/erb/scaffold/templates/edit.html.erb +1 -1
  47. data/lib/rails/generators/erb/scaffold/templates/index.html.erb +2 -2
  48. data/lib/rails/generators/erb/scaffold/templates/new.html.erb +1 -1
  49. data/lib/rails/generators/generated_attribute.rb +5 -1
  50. data/lib/rails/generators/migration.rb +7 -7
  51. data/lib/rails/generators/named_base.rb +21 -5
  52. data/lib/rails/generators/rails/app/USAGE +0 -1
  53. data/lib/rails/generators/rails/app/app_generator.rb +75 -11
  54. data/lib/rails/generators/rails/app/templates/Gemfile +17 -13
  55. data/lib/rails/generators/rails/app/templates/{README.rdoc → README.md} +1 -5
  56. data/lib/rails/generators/rails/app/templates/app/assets/config/manifest.js.tt +7 -0
  57. data/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +1 -1
  58. data/lib/rails/generators/rails/app/templates/app/assets/javascripts/cable.coffee +11 -0
  59. data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css +3 -3
  60. data/lib/rails/generators/rails/app/templates/app/channels/application_cable/channel.rb +5 -0
  61. data/lib/rails/generators/rails/app/templates/app/channels/application_cable/connection.rb +5 -0
  62. data/lib/rails/generators/rails/app/templates/app/controllers/application_controller.rb.tt +3 -1
  63. data/lib/rails/generators/rails/app/templates/app/jobs/application_job.rb +2 -0
  64. data/lib/rails/generators/rails/app/templates/app/mailers/application_mailer.rb +4 -0
  65. data/lib/rails/generators/rails/app/templates/app/models/application_record.rb +3 -0
  66. data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +20 -17
  67. data/lib/rails/generators/rails/app/templates/app/views/layouts/mailer.html.erb.tt +13 -0
  68. data/lib/rails/generators/{erb/mailer/templates/layout.text.erb → rails/app/templates/app/views/layouts/mailer.text.erb.tt} +0 -0
  69. data/lib/rails/generators/rails/app/templates/bin/setup +17 -12
  70. data/lib/rails/generators/rails/app/templates/bin/update +28 -0
  71. data/lib/rails/generators/rails/app/templates/config.ru.tt +11 -0
  72. data/lib/rails/generators/rails/app/templates/config/application.rb +9 -14
  73. data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml +1 -1
  74. data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml +2 -2
  75. data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +20 -3
  76. data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +18 -11
  77. data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +7 -3
  78. data/lib/rails/generators/rails/app/templates/config/initializers/active_record_belongs_to_required_by_default.rb +5 -0
  79. data/lib/rails/generators/rails/app/templates/config/initializers/application_controller_renderer.rb +6 -0
  80. data/lib/rails/generators/rails/app/templates/config/initializers/callback_terminator.rb +5 -0
  81. data/lib/rails/generators/rails/app/templates/config/initializers/cookies_serializer.rb +1 -0
  82. data/lib/rails/generators/rails/app/templates/config/initializers/cors.rb +16 -0
  83. data/lib/rails/generators/rails/app/templates/config/initializers/request_forgery_protection.rb +4 -0
  84. data/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt +2 -2
  85. data/lib/rails/generators/rails/app/templates/config/redis/cable.yml +9 -0
  86. data/lib/rails/generators/rails/app/templates/config/routes.rb +3 -53
  87. data/lib/rails/generators/rails/app/templates/db/seeds.rb.tt +3 -3
  88. data/lib/rails/generators/rails/app/templates/gitignore +7 -1
  89. data/lib/rails/generators/rails/controller/controller_generator.rb +6 -4
  90. data/lib/rails/generators/rails/migration/migration_generator.rb +1 -1
  91. data/lib/rails/generators/rails/model/USAGE +6 -1
  92. data/lib/rails/generators/rails/model/model_generator.rb +1 -1
  93. data/lib/rails/generators/rails/plugin/plugin_generator.rb +88 -35
  94. data/lib/rails/generators/rails/plugin/templates/%name%.gemspec +6 -9
  95. data/lib/rails/generators/rails/plugin/templates/Gemfile +3 -7
  96. data/lib/rails/generators/rails/plugin/templates/README.md +3 -0
  97. data/lib/rails/generators/rails/plugin/templates/Rakefile +2 -2
  98. data/lib/rails/generators/rails/plugin/templates/app/controllers/%namespaced_name%/application_controller.rb.tt +5 -0
  99. data/lib/rails/generators/rails/plugin/templates/app/helpers/%namespaced_name%/application_helper.rb.tt +5 -0
  100. data/lib/rails/generators/rails/plugin/templates/app/jobs/%namespaced_name%/application_job.rb.tt +5 -0
  101. data/lib/rails/generators/rails/plugin/templates/app/models/application_record.rb.tt +6 -0
  102. data/lib/rails/generators/rails/plugin/templates/app/views/layouts/%namespaced_name%/application.html.erb.tt +14 -0
  103. data/lib/rails/generators/rails/plugin/templates/bin/rails.tt +1 -1
  104. data/lib/rails/generators/rails/plugin/templates/bin/test.tt +8 -0
  105. data/lib/rails/generators/rails/plugin/templates/config/routes.rb +1 -1
  106. data/lib/rails/generators/rails/plugin/templates/gitignore +2 -3
  107. data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%.rb +5 -0
  108. data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/engine.rb +7 -0
  109. data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/version.rb +1 -0
  110. data/lib/rails/generators/rails/plugin/templates/lib/tasks/{%name%_tasks.rake → %namespaced_name%_tasks.rake} +1 -1
  111. data/lib/rails/generators/rails/plugin/templates/rails/application.rb +3 -3
  112. data/lib/rails/generators/rails/plugin/templates/rails/dummy_manifest.js +11 -0
  113. data/lib/rails/generators/rails/plugin/templates/rails/engine_manifest.js +6 -0
  114. data/lib/rails/generators/rails/plugin/templates/rails/javascripts.js +1 -1
  115. data/lib/rails/generators/rails/plugin/templates/rails/routes.rb +1 -2
  116. data/lib/rails/generators/rails/plugin/templates/rails/stylesheets.css +3 -3
  117. data/lib/rails/generators/rails/plugin/templates/test/%namespaced_name%_test.rb +7 -0
  118. data/lib/rails/generators/rails/plugin/templates/test/test_helper.rb +4 -2
  119. data/lib/rails/generators/rails/resource/resource_generator.rb +0 -1
  120. data/lib/rails/generators/rails/resource_route/resource_route_generator.rb +0 -1
  121. data/lib/rails/generators/rails/scaffold/USAGE +1 -1
  122. data/lib/rails/generators/rails/scaffold/scaffold_generator.rb +2 -1
  123. data/lib/rails/generators/rails/scaffold/templates/scaffold.css +35 -7
  124. data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +4 -1
  125. data/lib/rails/generators/rails/scaffold_controller/templates/api_controller.rb +61 -0
  126. data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb +1 -1
  127. data/lib/rails/generators/resource_helpers.rb +3 -3
  128. data/lib/rails/generators/test_unit/controller/templates/.functional_test.rb.swp +0 -0
  129. data/lib/rails/generators/test_unit/controller/templates/functional_test.rb +3 -5
  130. data/lib/rails/generators/test_unit/mailer/mailer_generator.rb +8 -3
  131. data/lib/rails/generators/test_unit/mailer/templates/functional_test.rb +2 -2
  132. data/lib/rails/generators/test_unit/mailer/templates/preview.rb +4 -4
  133. data/lib/rails/generators/test_unit/model/model_generator.rb +1 -1
  134. data/lib/rails/generators/test_unit/model/templates/fixtures.yml +2 -0
  135. data/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +5 -1
  136. data/lib/rails/generators/test_unit/scaffold/templates/.api_functional_test.rb.swp +0 -0
  137. data/lib/rails/generators/test_unit/scaffold/templates/.functional_test.rb.swp +0 -0
  138. data/lib/rails/generators/test_unit/scaffold/templates/api_functional_test.rb +44 -0
  139. data/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb +14 -14
  140. data/lib/rails/generators/testing/assertions.rb +0 -2
  141. data/lib/rails/generators/testing/behaviour.rb +4 -17
  142. data/lib/rails/info.rb +2 -2
  143. data/lib/rails/info_controller.rb +23 -2
  144. data/lib/rails/mailers_controller.rb +2 -2
  145. data/lib/rails/paths.rb +14 -6
  146. data/lib/rails/rack.rb +1 -3
  147. data/lib/rails/rack/debugger.rb +2 -23
  148. data/lib/rails/rack/logger.rb +4 -0
  149. data/lib/rails/ruby_version_check.rb +3 -3
  150. data/lib/rails/source_annotation_extractor.rb +1 -1
  151. data/lib/rails/tasks.rb +4 -1
  152. data/lib/rails/tasks/engine.rake +1 -1
  153. data/lib/rails/tasks/framework.rake +18 -16
  154. data/lib/rails/tasks/initializers.rake +6 -0
  155. data/lib/rails/tasks/restart.rake +5 -0
  156. data/lib/rails/tasks/statistics.rake +5 -6
  157. data/lib/rails/tasks/tmp.rake +4 -12
  158. data/lib/rails/templates/rails/mailers/email.html.erb +17 -3
  159. data/lib/rails/templates/rails/welcome/index.html.erb +10 -3
  160. data/lib/rails/test_help.rb +7 -8
  161. data/lib/rails/test_unit/minitest_plugin.rb +91 -0
  162. data/lib/rails/test_unit/reporter.rb +74 -0
  163. data/lib/rails/test_unit/test_requirer.rb +28 -0
  164. data/lib/rails/test_unit/testing.rake +18 -39
  165. metadata +80 -33
  166. data/lib/rails/deprecation.rb +0 -19
  167. data/lib/rails/generators/erb/mailer/templates/layout.html.erb +0 -5
  168. data/lib/rails/generators/rails/app/templates/config.ru +0 -4
  169. data/lib/rails/generators/rails/app/templates/config/initializers/to_time_preserves_timezone.rb +0 -10
  170. data/lib/rails/generators/rails/plugin/templates/README.rdoc +0 -3
  171. data/lib/rails/generators/rails/plugin/templates/app/controllers/%name%/application_controller.rb.tt +0 -5
  172. data/lib/rails/generators/rails/plugin/templates/app/helpers/%name%/application_helper.rb.tt +0 -4
  173. data/lib/rails/generators/rails/plugin/templates/app/views/layouts/%name%/application.html.erb.tt +0 -14
  174. data/lib/rails/generators/rails/plugin/templates/lib/%name%.rb +0 -6
  175. data/lib/rails/generators/rails/plugin/templates/lib/%name%/engine.rb +0 -7
  176. data/lib/rails/generators/rails/plugin/templates/lib/%name%/version.rb +0 -3
  177. data/lib/rails/generators/rails/plugin/templates/test/%name%_test.rb +0 -7
  178. data/lib/rails/rack/log_tailer.rb +0 -38
  179. data/lib/rails/tasks/documentation.rake +0 -70
  180. data/lib/rails/test_unit/sub_test_task.rb +0 -126
@@ -13,12 +13,14 @@ module Rails
13
13
  def add_routes
14
14
  unless options[:skip_routes]
15
15
  actions.reverse_each do |action|
16
- route generate_routing_code(action)
16
+ # route prepends two spaces onto the front of the string that is passed, this corrects that.
17
+ route generate_routing_code(action)[2..-1]
17
18
  end
18
19
  end
19
20
  end
20
21
 
21
- hook_for :template_engine, :test_framework, :helper, :assets
22
+ hook_for :template_engine, :test_framework
23
+ hook_for :helper, :assets, hide: true
22
24
 
23
25
  private
24
26
 
@@ -36,12 +38,12 @@ module Rails
36
38
  # namespace :foo do
37
39
  # namespace :bar do
38
40
  namespace_ladder = regular_class_path.each_with_index.map do |ns, i|
39
- indent("namespace :#{ns} do\n", i * 2)
41
+ indent(" namespace :#{ns} do\n", i * 2)
40
42
  end.join
41
43
 
42
44
  # Create route
43
45
  # get 'baz/index'
44
- route = indent(%{get '#{file_name}/#{action}'\n}, depth * 2)
46
+ route = indent(%{ get '#{file_name}/#{action}'\n}, depth * 2)
45
47
 
46
48
  # Create `end` ladder
47
49
  # end
@@ -2,7 +2,7 @@ module Rails
2
2
  module Generators
3
3
  class MigrationGenerator < NamedBase # :nodoc:
4
4
  argument :attributes, type: :array, default: [], banner: "field[:type][:index] field[:type][:index]"
5
- hook_for :orm, required: true
5
+ hook_for :orm, required: true, desc: "ORM to be invoked"
6
6
  end
7
7
  end
8
8
  end
@@ -79,10 +79,15 @@ Available field types:
79
79
  `rails generate model product supplier:references{polymorphic}:index`
80
80
 
81
81
  If you require a `password_digest` string column for use with
82
- has_secure_password, you should specify `password:digest`:
82
+ has_secure_password, you can specify `password:digest`:
83
83
 
84
84
  `rails generate model user password:digest`
85
85
 
86
+ If you require a `token` string column for use with
87
+ has_secure_token, you can specify `auth_token:token`:
88
+
89
+ `rails generate model user auth_token:token`
90
+
86
91
  Examples:
87
92
  `rails generate model account`
88
93
 
@@ -6,7 +6,7 @@ module Rails
6
6
  include Rails::Generators::ModelHelpers
7
7
 
8
8
  argument :attributes, type: :array, default: [], banner: "field[:type][:index] field[:type][:index]"
9
- hook_for :orm, required: true
9
+ hook_for :orm, required: true, desc: "ORM to be invoked"
10
10
  end
11
11
  end
12
12
  end
@@ -8,7 +8,7 @@ module Rails
8
8
  # generator.
9
9
  #
10
10
  # This allows you to override entire operations, like the creation of the
11
- # Gemfile, README, or JavaScript files, without needing to know exactly
11
+ # Gemfile, \README, or JavaScript files, without needing to know exactly
12
12
  # what those operations do so you can create another template action.
13
13
  class PluginBuilder
14
14
  def rakefile
@@ -17,20 +17,27 @@ module Rails
17
17
 
18
18
  def app
19
19
  if mountable?
20
- directory 'app'
21
- empty_directory_with_keep_file "app/assets/images/#{name}"
20
+ if api?
21
+ directory 'app', exclude_pattern: %r{app/(views|helpers)}
22
+ else
23
+ directory 'app'
24
+ empty_directory_with_keep_file "app/assets/images/#{namespaced_name}"
25
+ end
22
26
  elsif full?
23
27
  empty_directory_with_keep_file 'app/models'
24
28
  empty_directory_with_keep_file 'app/controllers'
25
- empty_directory_with_keep_file 'app/views'
26
- empty_directory_with_keep_file 'app/helpers'
27
29
  empty_directory_with_keep_file 'app/mailers'
28
- empty_directory_with_keep_file "app/assets/images/#{name}"
30
+
31
+ unless api?
32
+ empty_directory_with_keep_file "app/assets/images/#{namespaced_name}"
33
+ empty_directory_with_keep_file 'app/helpers'
34
+ empty_directory_with_keep_file 'app/views'
35
+ end
29
36
  end
30
37
  end
31
38
 
32
39
  def readme
33
- template "README.rdoc"
40
+ template "README.md"
34
41
  end
35
42
 
36
43
  def gemfile
@@ -50,10 +57,10 @@ module Rails
50
57
  end
51
58
 
52
59
  def lib
53
- template "lib/%name%.rb"
54
- template "lib/tasks/%name%_tasks.rake"
55
- template "lib/%name%/version.rb"
56
- template "lib/%name%/engine.rb" if engine?
60
+ template "lib/%namespaced_name%.rb"
61
+ template "lib/tasks/%namespaced_name%_tasks.rake"
62
+ template "lib/%namespaced_name%/version.rb"
63
+ template "lib/%namespaced_name%/engine.rb" if engine?
57
64
  end
58
65
 
59
66
  def config
@@ -62,7 +69,7 @@ module Rails
62
69
 
63
70
  def test
64
71
  template "test/test_helper.rb"
65
- template "test/%name%_test.rb"
72
+ template "test/%namespaced_name%_test.rb"
66
73
  append_file "Rakefile", <<-EOF
67
74
  #{rakefile_test_tasks}
68
75
 
@@ -74,13 +81,15 @@ task default: :test
74
81
  end
75
82
 
76
83
  PASSTHROUGH_OPTIONS = [
77
- :skip_active_record, :skip_javascript, :database, :javascript, :quiet, :pretend, :force, :skip
84
+ :skip_active_record, :skip_action_mailer, :skip_javascript, :database,
85
+ :javascript, :quiet, :pretend, :force, :skip
78
86
  ]
79
87
 
80
88
  def generate_test_dummy(force = false)
81
89
  opts = (options || {}).slice(*PASSTHROUGH_OPTIONS)
82
90
  opts[:force] = force
83
91
  opts[:skip_bundle] = true
92
+ opts[:api] = options.api?
84
93
 
85
94
  invoke Rails::Generators::AppGenerator,
86
95
  [ File.expand_path(dummy_path, destination_root) ], opts
@@ -95,8 +104,9 @@ task default: :test
95
104
  end
96
105
 
97
106
  def test_dummy_assets
98
- template "rails/javascripts.js", "#{dummy_path}/app/assets/javascripts/application.js", force: true
99
- template "rails/stylesheets.css", "#{dummy_path}/app/assets/stylesheets/application.css", force: true
107
+ template "rails/javascripts.js", "#{dummy_path}/app/assets/javascripts/application.js", force: true
108
+ template "rails/stylesheets.css", "#{dummy_path}/app/assets/stylesheets/application.css", force: true
109
+ template "rails/dummy_manifest.js", "#{dummy_path}/app/assets/config/manifest.js", force: true
100
110
  end
101
111
 
102
112
  def test_dummy_clean
@@ -107,18 +117,22 @@ task default: :test
107
117
  remove_file "Gemfile"
108
118
  remove_file "lib/tasks"
109
119
  remove_file "public/robots.txt"
110
- remove_file "README"
120
+ remove_file "README.md"
111
121
  remove_file "test"
112
122
  remove_file "vendor"
113
123
  end
114
124
  end
115
125
 
126
+ def assets_manifest
127
+ template "rails/engine_manifest.js", "app/assets/config/#{underscored_name}_manifest.js"
128
+ end
129
+
116
130
  def stylesheets
117
131
  if mountable?
118
132
  copy_file "rails/stylesheets.css",
119
- "app/assets/stylesheets/#{name}/application.css"
133
+ "app/assets/stylesheets/#{namespaced_name}/application.css"
120
134
  elsif full?
121
- empty_directory_with_keep_file "app/assets/stylesheets/#{name}"
135
+ empty_directory_with_keep_file "app/assets/stylesheets/#{namespaced_name}"
122
136
  end
123
137
  end
124
138
 
@@ -127,16 +141,15 @@ task default: :test
127
141
 
128
142
  if mountable?
129
143
  template "rails/javascripts.js",
130
- "app/assets/javascripts/#{name}/application.js"
144
+ "app/assets/javascripts/#{namespaced_name}/application.js"
131
145
  elsif full?
132
- empty_directory_with_keep_file "app/assets/javascripts/#{name}"
146
+ empty_directory_with_keep_file "app/assets/javascripts/#{namespaced_name}"
133
147
  end
134
148
  end
135
149
 
136
150
  def bin(force = false)
137
- return unless engine?
138
-
139
- directory "bin", force: force do |content|
151
+ bin_file = engine? ? 'bin/rails.tt' : 'bin/test.tt'
152
+ template bin_file, force: force do |content|
140
153
  "#{shebang}\n" + content
141
154
  end
142
155
  chmod "bin", 0755, verbose: false
@@ -175,6 +188,9 @@ task default: :test
175
188
  desc: "If creating plugin in application's directory " +
176
189
  "skip adding entry to Gemfile"
177
190
 
191
+ class_option :api, type: :boolean, default: false,
192
+ desc: "Generate a smaller stack for API application plugins"
193
+
178
194
  def initialize(*args)
179
195
  @dummy_path = nil
180
196
  super
@@ -208,16 +224,16 @@ task default: :test
208
224
  build(:lib)
209
225
  end
210
226
 
211
- def create_public_stylesheets_files
212
- build(:stylesheets)
227
+ def create_assets_manifest_file
228
+ build(:assets_manifest) if !api? && engine?
213
229
  end
214
230
 
215
- def create_javascript_files
216
- build(:javascripts)
231
+ def create_public_stylesheets_files
232
+ build(:stylesheets) unless api?
217
233
  end
218
234
 
219
- def create_images_directory
220
- build(:images)
235
+ def create_javascript_files
236
+ build(:javascripts) unless api?
221
237
  end
222
238
 
223
239
  def create_bin_files
@@ -225,7 +241,7 @@ task default: :test
225
241
  end
226
242
 
227
243
  def create_test_files
228
- build(:test) unless options[:skip_test_unit]
244
+ build(:test) unless options[:skip_test]
229
245
  end
230
246
 
231
247
  def create_test_dummy_files
@@ -241,7 +257,7 @@ task default: :test
241
257
  build(:leftovers)
242
258
  end
243
259
 
244
- public_task :apply_rails_template
260
+ public_task :apply_rails_template, :run_bundle
245
261
 
246
262
  def name
247
263
  @name ||= begin
@@ -255,6 +271,14 @@ task default: :test
255
271
  end
256
272
  end
257
273
 
274
+ def underscored_name
275
+ @underscored_name ||= original_name.underscore
276
+ end
277
+
278
+ def namespaced_name
279
+ @namespaced_name ||= name.gsub('-', '/')
280
+ end
281
+
258
282
  protected
259
283
 
260
284
  def app_templates_dir
@@ -293,7 +317,11 @@ task default: :test
293
317
  end
294
318
 
295
319
  def with_dummy_app?
296
- options[:skip_test_unit].blank? || options[:dummy_path] != 'test/dummy'
320
+ options[:skip_test].blank? || options[:dummy_path] != 'test/dummy'
321
+ end
322
+
323
+ def api?
324
+ options[:api]
297
325
  end
298
326
 
299
327
  def self.banner
@@ -304,6 +332,27 @@ task default: :test
304
332
  @original_name ||= File.basename(destination_root)
305
333
  end
306
334
 
335
+ def modules
336
+ @modules ||= namespaced_name.camelize.split("::")
337
+ end
338
+
339
+ def wrap_in_modules(unwrapped_code)
340
+ unwrapped_code = "#{unwrapped_code}".strip.gsub(/\W$\n/, '')
341
+ modules.reverse.inject(unwrapped_code) do |content, mod|
342
+ str = "module #{mod}\n"
343
+ str += content.lines.map { |line| " #{line}" }.join
344
+ str += content.present? ? "\nend" : "end"
345
+ end
346
+ end
347
+
348
+ def camelized_modules
349
+ @camelized_modules ||= namespaced_name.camelize
350
+ end
351
+
352
+ def humanized
353
+ @humanized ||= original_name.underscore.humanize
354
+ end
355
+
307
356
  def camelized
308
357
  @camelized ||= name.gsub(/\W/, '_').squeeze('_').camelize
309
358
  end
@@ -327,12 +376,16 @@ task default: :test
327
376
  end
328
377
 
329
378
  def valid_const?
330
- if original_name =~ /[^0-9a-zA-Z_]+/
331
- raise Error, "Invalid plugin name #{original_name}. Please give a name which use only alphabetic or numeric or \"_\" characters."
379
+ if original_name =~ /-\d/
380
+ raise Error, "Invalid plugin name #{original_name}. Please give a name which does not contain a namespace starting with numeric characters."
381
+ elsif original_name =~ /[^\w-]+/
382
+ raise Error, "Invalid plugin name #{original_name}. Please give a name which uses only alphabetic, numeric, \"_\" or \"-\" characters."
332
383
  elsif camelized =~ /^\d/
333
384
  raise Error, "Invalid plugin name #{original_name}. Please give a name which does not start with numbers."
334
385
  elsif RESERVED_NAMES.include?(name)
335
- raise Error, "Invalid plugin name #{original_name}. Please give a name which does not match one of the reserved rails words."
386
+ raise Error, "Invalid plugin name #{original_name}. Please give a " \
387
+ "name which does not match one of the reserved rails " \
388
+ "words: #{RESERVED_NAMES.join(", ")}"
336
389
  elsif Object.const_defined?(camelized)
337
390
  raise Error, "Invalid plugin name #{original_name}, constant #{camelized} is already in use. Please choose another plugin name."
338
391
  end
@@ -1,25 +1,22 @@
1
1
  $:.push File.expand_path("../lib", __FILE__)
2
2
 
3
3
  # Maintain your gem's version:
4
- require "<%= name %>/version"
4
+ require "<%= namespaced_name %>/version"
5
5
 
6
6
  # Describe your gem and declare its dependencies:
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "<%= name %>"
9
- s.version = <%= camelized %>::VERSION
9
+ s.version = <%= camelized_modules %>::VERSION
10
10
  s.authors = ["<%= author %>"]
11
11
  s.email = ["<%= email %>"]
12
12
  s.homepage = "TODO"
13
- s.summary = "TODO: Summary of <%= camelized %>."
14
- s.description = "TODO: Description of <%= camelized %>."
13
+ s.summary = "TODO: Summary of <%= camelized_modules %>."
14
+ s.description = "TODO: Description of <%= camelized_modules %>."
15
15
  s.license = "MIT"
16
16
 
17
- s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc"]
18
- <% unless options.skip_test_unit? -%>
19
- s.test_files = Dir["test/**/*"]
20
- <% end -%>
17
+ s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"]
21
18
 
22
- <%= '# ' if options.dev? || options.edge? -%>s.add_dependency "rails", "~> <%= Rails::VERSION::STRING %>"
19
+ <%= '# ' if options.dev? || options.edge? -%>s.add_dependency "rails", "<%= Array(rails_version_specifier).join('", "') %>"
23
20
  <% unless options[:skip_active_record] -%>
24
21
 
25
22
  s.add_development_dependency "<%= gem_for_database[0] %>"
@@ -1,7 +1,7 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  <% if options[:skip_gemspec] -%>
4
- <%= '# ' if options.dev? || options.edge? -%>gem 'rails', '~> <%= Rails::VERSION::STRING %>'
4
+ <%= '# ' if options.dev? || options.edge? -%>gem 'rails', '<%= Array(rails_version_specifier).join("', '") %>'
5
5
  <% else -%>
6
6
  # Declare your gem's dependencies in <%= name %>.gemspec.
7
7
  # Bundler will treat runtime dependencies like base dependencies, and
@@ -37,15 +37,11 @@ end
37
37
  <% end -%>
38
38
 
39
39
  <% end -%>
40
- <% unless defined?(JRUBY_VERSION) -%>
40
+ <% if RUBY_ENGINE == 'ruby' -%>
41
41
  # To use a debugger
42
- <%- if RUBY_VERSION < '2.0.0' -%>
43
- # gem 'debugger', group: [:development, :test]
44
- <%- else -%>
45
42
  # gem 'byebug', group: [:development, :test]
46
- <%- end -%>
47
43
  <% end -%>
48
-
49
44
  <% if RUBY_PLATFORM.match(/bccwin|cygwin|emx|mingw|mswin|wince|java/) -%>
45
+
50
46
  gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
51
47
  <% end -%>
@@ -0,0 +1,3 @@
1
+ # <%= camelized_modules %>
2
+
3
+ This project rocks and uses MIT-LICENSE.
@@ -8,9 +8,9 @@ require 'rdoc/task'
8
8
 
9
9
  RDoc::Task.new(:rdoc) do |rdoc|
10
10
  rdoc.rdoc_dir = 'rdoc'
11
- rdoc.title = '<%= camelized %>'
11
+ rdoc.title = '<%= camelized_modules %>'
12
12
  rdoc.options << '--line-numbers'
13
- rdoc.rdoc_files.include('README.rdoc')
13
+ rdoc.rdoc_files.include('README.md')
14
14
  rdoc.rdoc_files.include('lib/**/*.rb')
15
15
  end
16
16
 
@@ -0,0 +1,5 @@
1
+ <%= wrap_in_modules <<-rb.strip_heredoc
2
+ class ApplicationController < ActionController::#{api? ? "API" : "Base"}
3
+ end
4
+ rb
5
+ %>
@@ -0,0 +1,5 @@
1
+ <%= wrap_in_modules <<-rb.strip_heredoc
2
+ module ApplicationHelper
3
+ end
4
+ rb
5
+ %>
@@ -0,0 +1,5 @@
1
+ <%= wrap_in_modules <<-rb.strip_heredoc
2
+ class ApplicationJob < ActiveJob::Base
3
+ end
4
+ rb
5
+ %>
@@ -0,0 +1,6 @@
1
+ <%= wrap_in_modules <<-rb.strip_heredoc
2
+ class ApplicationRecord < ActiveRecord::Base
3
+ self.abstract_class = true
4
+ end
5
+ rb
6
+ %>
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title><%= humanized %></title>
5
+ <%%= stylesheet_link_tag "<%= namespaced_name %>/application", media: "all" %>
6
+ <%%= javascript_include_tag "<%= namespaced_name %>/application" %>
7
+ <%%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%%= yield %>
12
+
13
+ </body>
14
+ </html>