Ruby
Rails
Rails6

Rails6 のちょい足しな新機能を試す12(rails notes --annotation 編)


はじめに

Rails 6 に追加されそうな新機能を試す第12段。 今回のちょい足し機能は、 rails notes --annotations 編です。

rails notes コマンドに --annotations (-a) オプションが追加されました。

記載時点では、Rails は 6.0.0.rc1 です。 gem install rails --prerelease でインストールできます。

$  rails --version

Rails 6.0.0.rc1


プロジェクトを作成する

rails プロジェクトを作成します。

$ rails new sandbox6_0_0rc1


app/controllers/application_controller.rb にコメントを追加する

rails notes --annotations を試すためにコメントを追加します。


app/controllers/application_controller.rb

class ApplicationController < ActionController::Base

# TODO: add common method in controllers
# FIXME: fix the bug
# NOTE: this test for rails notes
end


rails notes --help を実行する

rails notes --help を実行すると --annotations(-a)` オプションがあることがわかります。

$ rails notes --help

Usage:
rails notes [options]

Options:
-a, [--annotations=one two three] # Filter by specific annotations, e.g. Foobar TODO
# Default: ["OPTIMIZE", "FIXME", "TODO"]


rails notes --annotations

--annotations オプションを試してみます。

$ rails notes --annotations FIXME NOTE

app/controllers/application_controller.rb:
* [3] [FIXME] fix the bug
* [4] [NOTE] this test for rails notes

-a でも同じ結果になります

$ rails notes -a FIXME NOTE

app/controllers/application_controller.rb:
* [3] [FIXME] fix the bug
* [4] [NOTE] this test for rails notes


おまけ

rails notes -a だけだとエラーになりました。

$ rails notes -a

Traceback (most recent call last):
30: from bin/rails:3:in `<main>'
29: from bin/rails:3:in `load'

28: from /app/sandbox6_0_0rc1/bin/spring:15:in `<top (required)>'
27: from /usr/local/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:65:in `require'

26: from /usr/local/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:65:in `require'
25: from /usr/local/bundle/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `<top (required)>'

24: from /usr/local/bundle/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `load'
23: from /usr/local/bundle/gems/spring-2.0.2/bin/spring:49:in `<top (required)>'

22: from /usr/local/bundle/gems/spring-2.0.2/lib/spring/client.rb:30:in `run'
21: from /usr/local/bundle/gems/spring-2.0.2/lib/spring/client/command.rb:7:in `call'

20: from /usr/local/bundle/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `call'
19: from /usr/local/bundle/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `load'

18: from /app/sandbox6_0_0rc1/bin/rails:9:in `<top (required)>'
17: from /usr/local/bundle/gems/activesupport-6.0.0.rc1/lib/active_support/dependencies.rb:302:in `require'

16: from /usr/local/bundle/gems/activesupport-6.0.0.rc1/lib/active_support/dependencies.rb:268:in `load_dependency'
15: from /usr/local/bundle/gems/activesupport-6.0.0.rc1/lib/active_support/dependencies.rb:302:in `block in require'

14: from /usr/local/bundle/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
13: from /usr/local/bundle/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'

12: from /usr/local/bundle/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
11: from /usr/local/bundle/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'

10: from /usr/local/bundle/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
9: from /usr/local/bundle/gems/railties-6.0.0.rc1/lib/rails/commands.rb:18:in `<main>'

8: from /usr/local/bundle/gems/railties-6.0.0.rc1/lib/rails/command.rb:46:in `invoke'
7: from /usr/local/bundle/gems/railties-6.0.0.rc1/lib/rails/command/base.rb:65:in `perform'

6: from /usr/local/bundle/gems/thor-0.20.3/lib/thor.rb:383:in `dispatch'
5: from /usr/local/bundle/gems/thor-0.20.3/lib/thor.rb:383:in `new'

4: from /usr/local/bundle/gems/thor-0.20.3/lib/thor/shell.rb:45:in `initialize'
3: from /usr/local/bundle/gems/thor-0.20.3/lib/thor/invocation.rb:25:in `initialize'

2: from /usr/local/bundle/gems/thor-0.20.3/lib/thor/base.rb:70:in `initialize'
1: from /usr/local/bundle/gems/thor-0.20.3/lib/thor/parser/options.rb:100:in `parse'

/usr/local/bundle/gems/thor-0.20.3/lib/thor/parser/options.rb:218:in `parse_peek': No value provided for option '--annotations' (Thor::MalformattedArgumentError)


参考情報