railties 5.0.7.2 → 5.1.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (197) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +77 -567
  3. data/MIT-LICENSE +1 -1
  4. data/RDOC_MAIN.rdoc +3 -3
  5. data/README.rdoc +1 -1
  6. data/exe/rails +2 -2
  7. data/lib/rails.rb +18 -18
  8. data/lib/rails/all.rb +1 -1
  9. data/lib/rails/api/generator.rb +28 -0
  10. data/lib/rails/api/task.rb +54 -42
  11. data/lib/rails/app_loader.rb +9 -9
  12. data/lib/rails/application.rb +30 -35
  13. data/lib/rails/application/bootstrap.rb +13 -7
  14. data/lib/rails/application/configuration.rb +30 -53
  15. data/lib/rails/application/default_middleware_stack.rb +3 -5
  16. data/lib/rails/application/finisher.rb +16 -7
  17. data/lib/rails/application/routes_reloader.rb +16 -1
  18. data/lib/rails/application_controller.rb +10 -10
  19. data/lib/rails/backtrace_cleaner.rb +5 -5
  20. data/lib/rails/cli.rb +7 -5
  21. data/lib/rails/code_statistics.rb +16 -17
  22. data/lib/rails/code_statistics_calculator.rb +3 -3
  23. data/lib/rails/command.rb +111 -0
  24. data/lib/rails/command/actions.rb +42 -0
  25. data/lib/rails/command/base.rb +149 -0
  26. data/lib/rails/command/behavior.rb +123 -0
  27. data/lib/rails/command/environment_argument.rb +34 -0
  28. data/lib/rails/commands.rb +2 -4
  29. data/lib/rails/commands/application/application_command.rb +29 -0
  30. data/lib/rails/commands/console/console_command.rb +89 -0
  31. data/lib/rails/commands/dbconsole/dbconsole_command.rb +155 -0
  32. data/lib/rails/commands/destroy/destroy_command.rb +21 -0
  33. data/lib/rails/commands/generate/generate_command.rb +23 -0
  34. data/lib/rails/commands/help/USAGE +15 -0
  35. data/lib/rails/commands/help/help_command.rb +13 -0
  36. data/lib/rails/commands/new/new_command.rb +15 -0
  37. data/lib/rails/commands/plugin/plugin_command.rb +43 -0
  38. data/lib/rails/commands/rake/rake_command.rb +49 -0
  39. data/lib/rails/commands/runner/USAGE +17 -0
  40. data/lib/rails/commands/runner/runner_command.rb +46 -0
  41. data/lib/rails/commands/secrets/USAGE +52 -0
  42. data/lib/rails/commands/secrets/secrets_command.rb +36 -0
  43. data/lib/rails/commands/server/server_command.rb +177 -0
  44. data/lib/rails/commands/test/test_command.rb +20 -0
  45. data/lib/rails/commands/version/version_command.rb +9 -0
  46. data/lib/rails/configuration.rb +7 -7
  47. data/lib/rails/console/app.rb +4 -4
  48. data/lib/rails/dev_caching.rb +8 -8
  49. data/lib/rails/engine.rb +62 -63
  50. data/lib/rails/engine/commands.rb +6 -13
  51. data/lib/rails/engine/configuration.rb +2 -2
  52. data/lib/rails/gem_version.rb +3 -3
  53. data/lib/rails/generators.rb +229 -313
  54. data/lib/rails/generators/actions.rb +20 -21
  55. data/lib/rails/generators/actions/create_migration.rb +24 -25
  56. data/lib/rails/generators/active_model.rb +3 -3
  57. data/lib/rails/generators/app_base.rb +123 -93
  58. data/lib/rails/generators/base.rb +32 -33
  59. data/lib/rails/generators/css/assets/assets_generator.rb +1 -1
  60. data/lib/rails/generators/erb.rb +14 -14
  61. data/lib/rails/generators/erb/controller/controller_generator.rb +1 -1
  62. data/lib/rails/generators/erb/mailer/mailer_generator.rb +12 -12
  63. data/lib/rails/generators/erb/scaffold/scaffold_generator.rb +3 -3
  64. data/lib/rails/generators/generated_attribute.rb +27 -27
  65. data/lib/rails/generators/js/assets/assets_generator.rb +1 -1
  66. data/lib/rails/generators/migration.rb +8 -8
  67. data/lib/rails/generators/model_helpers.rb +2 -2
  68. data/lib/rails/generators/named_base.rb +56 -56
  69. data/lib/rails/generators/rails/app/app_generator.rb +98 -81
  70. data/lib/rails/generators/rails/app/templates/Gemfile +7 -2
  71. data/lib/rails/generators/rails/app/templates/app/assets/config/manifest.js.tt +0 -2
  72. data/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +6 -4
  73. data/lib/rails/generators/rails/app/templates/app/assets/javascripts/cable.js +1 -1
  74. data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css +2 -2
  75. data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +1 -1
  76. data/lib/rails/generators/rails/app/templates/bin/{setup → setup.tt} +6 -0
  77. data/lib/rails/generators/rails/app/templates/bin/{update → update.tt} +2 -1
  78. data/lib/rails/generators/rails/app/templates/bin/yarn +9 -0
  79. data/lib/rails/generators/rails/app/templates/config/cable.yml +1 -0
  80. data/lib/rails/generators/rails/app/templates/config/databases/frontbase.yml +1 -0
  81. data/lib/rails/generators/rails/app/templates/config/databases/ibm_db.yml +1 -0
  82. data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml +1 -0
  83. data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml +2 -1
  84. data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml +1 -0
  85. data/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml +1 -0
  86. data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml +2 -2
  87. data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml +1 -0
  88. data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml +1 -1
  89. data/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml +1 -1
  90. data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +1 -1
  91. data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +10 -1
  92. data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +1 -1
  93. data/lib/rails/generators/rails/app/templates/config/initializers/application_controller_renderer.rb +4 -6
  94. data/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt +8 -3
  95. data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults.rb.tt +6 -5
  96. data/lib/rails/generators/rails/app/templates/config/locales/en.yml +10 -0
  97. data/lib/rails/generators/rails/app/templates/config/puma.rb +16 -7
  98. data/lib/rails/generators/rails/app/templates/config/secrets.yml +12 -2
  99. data/lib/rails/generators/rails/app/templates/gitignore +5 -1
  100. data/lib/rails/generators/rails/app/templates/package.json +5 -0
  101. data/lib/rails/generators/rails/app/templates/public/404.html +6 -6
  102. data/lib/rails/generators/rails/app/templates/public/422.html +6 -6
  103. data/lib/rails/generators/rails/app/templates/public/500.html +6 -6
  104. data/lib/rails/generators/rails/app/templates/public/robots.txt +0 -4
  105. data/lib/rails/generators/rails/app/templates/test/application_system_test_case.rb +5 -0
  106. data/lib/rails/generators/rails/app/templates/test/test_helper.rb +0 -1
  107. data/lib/rails/generators/rails/assets/assets_generator.rb +10 -10
  108. data/lib/rails/generators/rails/controller/controller_generator.rb +15 -12
  109. data/lib/rails/generators/rails/encrypted_secrets/encrypted_secrets_generator.rb +66 -0
  110. data/lib/rails/generators/rails/encrypted_secrets/templates/config/secrets.yml.enc +3 -0
  111. data/lib/rails/generators/rails/generator/generator_generator.rb +2 -3
  112. data/lib/rails/generators/rails/helper/helper_generator.rb +1 -1
  113. data/lib/rails/generators/rails/model/model_generator.rb +1 -1
  114. data/lib/rails/generators/rails/plugin/plugin_generator.rb +21 -26
  115. data/lib/rails/generators/rails/plugin/templates/bin/rails.tt +1 -0
  116. data/lib/rails/generators/rails/plugin/templates/bin/test.tt +3 -9
  117. data/lib/rails/generators/rails/plugin/templates/test/application_system_test_case.rb +5 -0
  118. data/lib/rails/generators/rails/plugin/templates/test/test_helper.rb +0 -3
  119. data/lib/rails/generators/rails/resource/resource_generator.rb +2 -2
  120. data/lib/rails/generators/rails/scaffold/scaffold_generator.rb +5 -1
  121. data/lib/rails/generators/rails/scaffold/templates/scaffold.css +4 -8
  122. data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +2 -3
  123. data/lib/rails/generators/rails/system_test/USAGE +10 -0
  124. data/lib/rails/generators/rails/system_test/system_test_generator.rb +7 -0
  125. data/lib/rails/generators/rails/task/task_generator.rb +1 -2
  126. data/lib/rails/generators/resource_helpers.rb +13 -10
  127. data/lib/rails/generators/test_case.rb +5 -6
  128. data/lib/rails/generators/test_unit.rb +1 -1
  129. data/lib/rails/generators/test_unit/controller/controller_generator.rb +3 -3
  130. data/lib/rails/generators/test_unit/generator/generator_generator.rb +3 -3
  131. data/lib/rails/generators/test_unit/helper/helper_generator.rb +1 -1
  132. data/lib/rails/generators/test_unit/integration/integration_generator.rb +2 -2
  133. data/lib/rails/generators/test_unit/job/job_generator.rb +3 -3
  134. data/lib/rails/generators/test_unit/mailer/mailer_generator.rb +5 -5
  135. data/lib/rails/generators/test_unit/model/model_generator.rb +3 -4
  136. data/lib/rails/generators/test_unit/plugin/plugin_generator.rb +2 -2
  137. data/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +3 -3
  138. data/lib/rails/generators/test_unit/system/system_generator.rb +17 -0
  139. data/lib/rails/generators/test_unit/system/templates/application_system_test_case.rb +5 -0
  140. data/lib/rails/generators/test_unit/system/templates/system_test.rb +9 -0
  141. data/lib/rails/generators/testing/assertions.rb +4 -4
  142. data/lib/rails/generators/testing/behaviour.rb +20 -21
  143. data/lib/rails/info.rb +20 -20
  144. data/lib/rails/info_controller.rb +15 -15
  145. data/lib/rails/initializable.rb +6 -2
  146. data/lib/rails/mailers_controller.rb +11 -11
  147. data/lib/rails/paths.rb +4 -5
  148. data/lib/rails/plugin/test.rb +7 -0
  149. data/lib/rails/rack/logger.rb +44 -46
  150. data/lib/rails/railtie.rb +41 -38
  151. data/lib/rails/railtie/configurable.rb +6 -6
  152. data/lib/rails/railtie/configuration.rb +1 -1
  153. data/lib/rails/ruby_version_check.rb +1 -1
  154. data/lib/rails/secrets.rb +111 -0
  155. data/lib/rails/source_annotation_extractor.rb +15 -9
  156. data/lib/rails/tasks.rb +3 -2
  157. data/lib/rails/tasks/annotations.rake +3 -3
  158. data/lib/rails/tasks/dev.rake +2 -2
  159. data/lib/rails/tasks/engine.rake +4 -4
  160. data/lib/rails/tasks/framework.rake +4 -18
  161. data/lib/rails/tasks/initializers.rake +1 -1
  162. data/lib/rails/tasks/log.rake +14 -10
  163. data/lib/rails/tasks/middleware.rake +1 -1
  164. data/lib/rails/tasks/misc.rake +10 -10
  165. data/lib/rails/tasks/restart.rake +4 -4
  166. data/lib/rails/tasks/routes.rake +3 -12
  167. data/lib/rails/tasks/statistics.rake +3 -3
  168. data/lib/rails/tasks/tmp.rake +7 -7
  169. data/lib/rails/tasks/yarn.rake +11 -0
  170. data/lib/rails/templates/rails/mailers/email.html.erb +4 -1
  171. data/lib/rails/test_help.rb +28 -10
  172. data/lib/rails/test_unit/line_filtering.rb +69 -3
  173. data/lib/rails/test_unit/minitest_plugin.rb +139 -0
  174. data/lib/rails/test_unit/railtie.rb +2 -1
  175. data/lib/rails/test_unit/reporter.rb +3 -8
  176. data/lib/rails/test_unit/test_requirer.rb +28 -0
  177. data/lib/rails/test_unit/testing.rake +19 -14
  178. data/lib/rails/version.rb +1 -1
  179. data/lib/rails/welcome_controller.rb +1 -1
  180. metadata +53 -30
  181. data/lib/minitest/rails_plugin.rb +0 -49
  182. data/lib/rails/commands/application.rb +0 -17
  183. data/lib/rails/commands/commands_tasks.rb +0 -180
  184. data/lib/rails/commands/console.rb +0 -68
  185. data/lib/rails/commands/console_helper.rb +0 -34
  186. data/lib/rails/commands/dbconsole.rb +0 -173
  187. data/lib/rails/commands/destroy.rb +0 -11
  188. data/lib/rails/commands/generate.rb +0 -13
  189. data/lib/rails/commands/plugin.rb +0 -23
  190. data/lib/rails/commands/rake_proxy.rb +0 -41
  191. data/lib/rails/commands/runner.rb +0 -71
  192. data/lib/rails/commands/server.rb +0 -163
  193. data/lib/rails/commands/test.rb +0 -10
  194. data/lib/rails/engine/commands_tasks.rb +0 -118
  195. data/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt +0 -3
  196. data/lib/rails/rack/debugger.rb +0 -3
  197. data/lib/rails/test_unit/runner.rb +0 -141
@@ -1,7 +1,7 @@
1
- require 'rails/initializable'
2
- require 'active_support/inflector'
3
- require 'active_support/core_ext/module/introspection'
4
- require 'active_support/core_ext/module/delegation'
1
+ require "rails/initializable"
2
+ require "active_support/inflector"
3
+ require "active_support/core_ext/module/introspection"
4
+ require "active_support/core_ext/module/delegation"
5
5
 
6
6
  module Rails
7
7
  # <tt>Rails::Railtie</tt> is the core of the Rails framework and provides
@@ -111,7 +111,7 @@ module Rails
111
111
  #
112
112
  # Be sure to look at the documentation of those specific classes for more information.
113
113
  class Railtie
114
- autoload :Configuration, 'rails/railtie/configuration'
114
+ autoload :Configuration, "rails/railtie/configuration"
115
115
 
116
116
  include Initializable
117
117
 
@@ -132,27 +132,19 @@ module Rails
132
132
  end
133
133
 
134
134
  def rake_tasks(&blk)
135
- @rake_tasks ||= []
136
- @rake_tasks << blk if blk
137
- @rake_tasks
135
+ register_block_for(:rake_tasks, &blk)
138
136
  end
139
137
 
140
138
  def console(&blk)
141
- @load_console ||= []
142
- @load_console << blk if blk
143
- @load_console
139
+ register_block_for(:load_console, &blk)
144
140
  end
145
141
 
146
142
  def runner(&blk)
147
- @load_runner ||= []
148
- @load_runner << blk if blk
149
- @load_runner
143
+ register_block_for(:runner, &blk)
150
144
  end
151
145
 
152
146
  def generators(&blk)
153
- @generators ||= []
154
- @generators << blk if blk
155
- @generators
147
+ register_block_for(:generators, &blk)
156
148
  end
157
149
 
158
150
  def abstract_railtie?
@@ -181,8 +173,8 @@ module Rails
181
173
  instance.configure(&block)
182
174
  end
183
175
 
184
- protected
185
- def generate_railtie_name(string) #:nodoc:
176
+ private
177
+ def generate_railtie_name(string)
186
178
  ActiveSupport::Inflector.underscore(string).tr("/", "_")
187
179
  end
188
180
 
@@ -195,6 +187,16 @@ module Rails
195
187
  super
196
188
  end
197
189
  end
190
+
191
+ # receives an instance variable identifier, set the variable value if is
192
+ # blank and append given block to value, which will be used later in
193
+ # `#each_registered_block(type, &block)`
194
+ def register_block_for(type, &blk)
195
+ var_name = "@#{type}"
196
+ blocks = instance_variable_defined?(var_name) ? instance_variable_get(var_name) : instance_variable_set(var_name, [])
197
+ blocks << blk if blk
198
+ blocks
199
+ end
198
200
  end
199
201
 
200
202
  delegate :railtie_name, to: :class
@@ -222,31 +224,32 @@ module Rails
222
224
 
223
225
  protected
224
226
 
225
- def run_console_blocks(app) #:nodoc:
226
- each_registered_block(:console) { |block| block.call(app) }
227
- end
227
+ def run_console_blocks(app) #:nodoc:
228
+ each_registered_block(:console) { |block| block.call(app) }
229
+ end
228
230
 
229
- def run_generators_blocks(app) #:nodoc:
230
- each_registered_block(:generators) { |block| block.call(app) }
231
- end
231
+ def run_generators_blocks(app) #:nodoc:
232
+ each_registered_block(:generators) { |block| block.call(app) }
233
+ end
232
234
 
233
- def run_runner_blocks(app) #:nodoc:
234
- each_registered_block(:runner) { |block| block.call(app) }
235
- end
235
+ def run_runner_blocks(app) #:nodoc:
236
+ each_registered_block(:runner) { |block| block.call(app) }
237
+ end
236
238
 
237
- def run_tasks_blocks(app) #:nodoc:
238
- extend Rake::DSL
239
- each_registered_block(:rake_tasks) { |block| instance_exec(app, &block) }
240
- end
239
+ def run_tasks_blocks(app) #:nodoc:
240
+ extend Rake::DSL
241
+ each_registered_block(:rake_tasks) { |block| instance_exec(app, &block) }
242
+ end
241
243
 
242
244
  private
243
245
 
244
- def each_registered_block(type, &block)
245
- klass = self.class
246
- while klass.respond_to?(type)
247
- klass.public_send(type).each(&block)
248
- klass = klass.superclass
246
+ # run `&block` in every registered block in `#register_block_for`
247
+ def each_registered_block(type, &block)
248
+ klass = self.class
249
+ while klass.respond_to?(type)
250
+ klass.public_send(type).each(&block)
251
+ klass = klass.superclass
252
+ end
249
253
  end
250
- end
251
254
  end
252
255
  end
@@ -1,4 +1,4 @@
1
- require 'active_support/concern'
1
+ require "active_support/concern"
2
2
 
3
3
  module Rails
4
4
  class Railtie
@@ -9,7 +9,7 @@ module Rails
9
9
  delegate :config, to: :instance
10
10
 
11
11
  def inherited(base)
12
- raise "You cannot inherit from a #{self.superclass.name} child"
12
+ raise "You cannot inherit from a #{superclass.name} child"
13
13
  end
14
14
 
15
15
  def instance
@@ -24,11 +24,11 @@ module Rails
24
24
  class_eval(&block)
25
25
  end
26
26
 
27
- protected
27
+ private
28
28
 
29
- def method_missing(*args, &block)
30
- instance.send(*args, &block)
31
- end
29
+ def method_missing(*args, &block)
30
+ instance.send(*args, &block)
31
+ end
32
32
  end
33
33
  end
34
34
  end
@@ -1,4 +1,4 @@
1
- require 'rails/configuration'
1
+ require "rails/configuration"
2
2
 
3
3
  module Rails
4
4
  class Railtie
@@ -1,4 +1,4 @@
1
- if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.2.2') && RUBY_ENGINE == 'ruby'
1
+ if RUBY_VERSION < "2.2.2" && RUBY_ENGINE == "ruby"
2
2
  desc = defined?(RUBY_DESCRIPTION) ? RUBY_DESCRIPTION : "ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE})"
3
3
  abort <<-end_message
4
4
 
@@ -0,0 +1,111 @@
1
+ require "yaml"
2
+
3
+ module Rails
4
+ # Greatly inspired by Ara T. Howard's magnificent sekrets gem. 😘
5
+ class Secrets # :nodoc:
6
+ class MissingKeyError < RuntimeError
7
+ def initialize
8
+ super(<<-end_of_message.squish)
9
+ Missing encryption key to decrypt secrets with.
10
+ Ask your team for your master key and put it in ENV["RAILS_MASTER_KEY"]
11
+ end_of_message
12
+ end
13
+ end
14
+
15
+ @read_encrypted_secrets = false
16
+ @root = File # Wonky, but ensures `join` uses the current directory.
17
+
18
+ class << self
19
+ attr_writer :root
20
+ attr_accessor :read_encrypted_secrets
21
+
22
+ def parse(paths, env:)
23
+ paths.each_with_object(Hash.new) do |path, all_secrets|
24
+ require "erb"
25
+
26
+ secrets = YAML.load(ERB.new(preprocess(path)).result) || {}
27
+ all_secrets.merge!(secrets["shared"].deep_symbolize_keys) if secrets["shared"]
28
+ all_secrets.merge!(secrets[env].deep_symbolize_keys) if secrets[env]
29
+ end
30
+ end
31
+
32
+ def generate_key
33
+ cipher = new_cipher
34
+ SecureRandom.hex(cipher.key_len)[0, cipher.key_len]
35
+ end
36
+
37
+ def key
38
+ ENV["RAILS_MASTER_KEY"] || read_key_file || handle_missing_key
39
+ end
40
+
41
+ def encrypt(text)
42
+ cipher(:encrypt, text)
43
+ end
44
+
45
+ def decrypt(data)
46
+ cipher(:decrypt, data)
47
+ end
48
+
49
+ def read
50
+ decrypt(IO.binread(path))
51
+ end
52
+
53
+ def write(contents)
54
+ IO.binwrite("#{path}.tmp", encrypt(contents))
55
+ FileUtils.mv("#{path}.tmp", path)
56
+ end
57
+
58
+ def read_for_editing
59
+ tmp_path = File.join(Dir.tmpdir, File.basename(path))
60
+ IO.binwrite(tmp_path, read)
61
+
62
+ yield tmp_path
63
+
64
+ write(IO.binread(tmp_path))
65
+ ensure
66
+ FileUtils.rm(tmp_path) if File.exist?(tmp_path)
67
+ end
68
+
69
+ private
70
+ def handle_missing_key
71
+ raise MissingKeyError
72
+ end
73
+
74
+ def read_key_file
75
+ if File.exist?(key_path)
76
+ IO.binread(key_path).strip
77
+ end
78
+ end
79
+
80
+ def key_path
81
+ @root.join("config", "secrets.yml.key")
82
+ end
83
+
84
+ def path
85
+ @root.join("config", "secrets.yml.enc").to_s
86
+ end
87
+
88
+ def preprocess(path)
89
+ if path.end_with?(".enc")
90
+ if @read_encrypted_secrets
91
+ decrypt(IO.binread(path))
92
+ else
93
+ ""
94
+ end
95
+ else
96
+ IO.read(path)
97
+ end
98
+ end
99
+
100
+ def new_cipher
101
+ OpenSSL::Cipher.new("aes-256-cbc")
102
+ end
103
+
104
+ def cipher(mode, data)
105
+ cipher = new_cipher.public_send(mode)
106
+ cipher.key = key
107
+ cipher.update(data) << cipher.final
108
+ end
109
+ end
110
+ end
111
+ end
@@ -1,9 +1,9 @@
1
1
  # Implements the logic behind the rake tasks for annotations like
2
2
  #
3
- # rake notes
4
- # rake notes:optimize
3
+ # rails notes
4
+ # rails notes:optimize
5
5
  #
6
- # and friends. See <tt>rake -T notes</tt> and <tt>railties/lib/rails/tasks/annotations.rake</tt>.
6
+ # and friends. See <tt>rails -T notes</tt> and <tt>railties/lib/rails/tasks/annotations.rake</tt>.
7
7
  #
8
8
  # Annotation objects are triplets <tt>:line</tt>, <tt>:tag</tt>, <tt>:text</tt> that
9
9
  # represent the line where the annotation lives, its tag, and its text. Note
@@ -13,9 +13,15 @@
13
13
  # start with the tag optionally followed by a colon. Everything up to the end
14
14
  # of the line (or closing ERB comment tag) is considered to be their text.
15
15
  class SourceAnnotationExtractor
16
- class Annotation < Struct.new(:line, :tag, :text)
16
+ Annotation = Struct.new(:line, :tag, :text) do
17
17
  def self.directories
18
- @@directories ||= %w(app config db lib test) + (ENV['SOURCE_ANNOTATION_DIRECTORIES'] || '').split(',')
18
+ @@directories ||= %w(app config db lib test) + (ENV["SOURCE_ANNOTATION_DIRECTORIES"] || "").split(",")
19
+ end
20
+
21
+ # Registers additional directories to be included
22
+ # SourceAnnotationExtractor::Annotation.register_directories("spec","another")
23
+ def self.register_directories(*dirs)
24
+ directories.push(*dirs)
19
25
  end
20
26
 
21
27
  def self.extensions
@@ -38,7 +44,7 @@ class SourceAnnotationExtractor
38
44
  #
39
45
  # If +options+ has a flag <tt>:tag</tt> the tag is shown as in the example above.
40
46
  # Otherwise the string contains just line and text.
41
- def to_s(options={})
47
+ def to_s(options = {})
42
48
  s = "[#{line.to_s.rjust(options[:indent])}] "
43
49
  s << "[#{tag}] " if options[:tag]
44
50
  s << text
@@ -60,7 +66,7 @@ class SourceAnnotationExtractor
60
66
  # See <tt>#find_in</tt> for a list of file extensions that will be taken into account.
61
67
  #
62
68
  # This class method is the single entry point for the rake tasks.
63
- def self.enumerate(tag, options={})
69
+ def self.enumerate(tag, options = {})
64
70
  extractor = new(tag)
65
71
  dirs = options.delete(:dirs) || Annotation.directories
66
72
  extractor.display(extractor.find(dirs), options)
@@ -110,7 +116,7 @@ class SourceAnnotationExtractor
110
116
  # Otherwise it returns an empty hash.
111
117
  def extract_annotations_from(file, pattern)
112
118
  lineno = 0
113
- result = File.readlines(file).inject([]) do |list, line|
119
+ result = File.readlines(file, encoding: Encoding::BINARY).inject([]) do |list, line|
114
120
  lineno += 1
115
121
  next list unless line =~ pattern
116
122
  list << Annotation.new(lineno, $1, $2)
@@ -120,7 +126,7 @@ class SourceAnnotationExtractor
120
126
 
121
127
  # Prints the mapping from filenames to annotations in +results+ ordered by filename.
122
128
  # The +options+ hash is passed to each annotation's +to_s+.
123
- def display(results, options={})
129
+ def display(results, options = {})
124
130
  options[:indent] = results.flat_map { |f, a| a.map(&:line) }.max.to_s.size
125
131
  results.keys.sort.each do |file|
126
132
  puts "#{file}:"
@@ -1,4 +1,4 @@
1
- require 'rake'
1
+ require "rake"
2
2
 
3
3
  # Load Rails Rakefile extensions
4
4
  %w(
@@ -12,8 +12,9 @@ require 'rake'
12
12
  restart
13
13
  routes
14
14
  tmp
15
+ yarn
15
16
  ).tap { |arr|
16
- arr << 'statistics' if Rake.application.current_scope.empty?
17
+ arr << "statistics" if Rake.application.current_scope.empty?
17
18
  }.each do |task|
18
19
  load "rails/tasks/#{task}.rake"
19
20
  end
@@ -1,4 +1,4 @@
1
- require 'rails/source_annotation_extractor'
1
+ require "rails/source_annotation_extractor"
2
2
 
3
3
  desc "Enumerate all annotations (use notes:optimize, :fixme, :todo for focus)"
4
4
  task :notes do
@@ -15,6 +15,6 @@ namespace :notes do
15
15
 
16
16
  desc "Enumerate a custom annotation, specify with ANNOTATION=CUSTOM"
17
17
  task :custom do
18
- SourceAnnotationExtractor.enumerate ENV['ANNOTATION']
18
+ SourceAnnotationExtractor.enumerate ENV["ANNOTATION"]
19
19
  end
20
- end
20
+ end
@@ -1,7 +1,7 @@
1
- require 'rails/dev_caching'
1
+ require "rails/dev_caching"
2
2
 
3
3
  namespace :dev do
4
- desc 'Toggle development mode caching on/off'
4
+ desc "Toggle development mode caching on/off"
5
5
  task :cache do
6
6
  Rails::DevCaching.enable_by_file
7
7
  end
@@ -2,7 +2,7 @@ task "load_app" do
2
2
  namespace :app do
3
3
  load APP_RAKEFILE
4
4
  end
5
- task :environment => "app:environment"
5
+ task environment: "app:environment"
6
6
 
7
7
  if !defined?(ENGINE_ROOT) || !ENGINE_ROOT
8
8
  ENGINE_ROOT = find_engine_path(APP_RAKEFILE)
@@ -26,11 +26,11 @@ namespace :db do
26
26
  desc "Display status of migrations"
27
27
  app_task "migrate:status"
28
28
 
29
- desc 'Create the database from config/database.yml for the current Rails.env (use db:create:all to create all databases in the config)'
29
+ desc "Create the database from config/database.yml for the current Rails.env (use db:create:all to create all databases in the config)"
30
30
  app_task "create"
31
31
  app_task "create:all"
32
32
 
33
- desc 'Drops the database for the current Rails.env (use db:drop:all to drop all databases)'
33
+ desc "Drops the database for the current Rails.env (use db:drop:all to drop all databases)"
34
34
  app_task "drop"
35
35
  app_task "drop:all"
36
36
 
@@ -65,7 +65,7 @@ def find_engine_path(path)
65
65
  if Rails::Engine.find(path)
66
66
  path
67
67
  else
68
- find_engine_path(File.expand_path('..', path))
68
+ find_engine_path(File.expand_path("..", path))
69
69
  end
70
70
  end
71
71
 
@@ -1,5 +1,3 @@
1
- require 'active_support/deprecation'
2
-
3
1
  namespace :app do
4
2
  desc "Update configs and some other initially generated files (or use just update:configs or update:bin)"
5
3
  task update: [ "update:configs", "update:bin", "update:upgrade_guide_info" ]
@@ -9,8 +7,8 @@ namespace :app do
9
7
  template = ENV["LOCATION"]
10
8
  raise "No LOCATION value given. Please set LOCATION either as path to a file or a URL" if template.blank?
11
9
  template = File.expand_path(template) if template !~ %r{\A[A-Za-z][A-Za-z0-9+\-\.]*://}
12
- require 'rails/generators'
13
- require 'rails/generators/rails/app/app_generator'
10
+ require "rails/generators"
11
+ require "rails/generators/rails/app/app_generator"
14
12
  generator = Rails::Generators::AppGenerator.new [Rails.root], {}, destination_root: Rails.root
15
13
  generator.apply template, verbose: false
16
14
  end
@@ -45,8 +43,8 @@ namespace :app do
45
43
 
46
44
  def self.app_generator
47
45
  @app_generator ||= begin
48
- require 'rails/generators'
49
- require 'rails/generators/rails/app/app_generator'
46
+ require "rails/generators"
47
+ require "rails/generators/rails/app/app_generator"
50
48
  gen = Rails::Generators::AppGenerator.new ["rails"],
51
49
  { api: !!Rails.application.config.api_only, update: true },
52
50
  destination_root: Rails.root
@@ -73,15 +71,3 @@ namespace :app do
73
71
  end
74
72
  end
75
73
  end
76
-
77
- namespace :rails do
78
- %i(update template templates:copy update:configs update:bin).each do |task_name|
79
- task "#{task_name}" do
80
- ActiveSupport::Deprecation.warn(<<-MSG.squish)
81
- Running #{task_name} with the rails: namespace is deprecated in favor of app: namespace.
82
- Run bin/rails app:#{task_name} instead.
83
- MSG
84
- Rake.application.invoke_task("app:#{task_name}")
85
- end
86
- end
87
- end