Ruby開発支援 - rcodetools - xmpfilter
さて、昨日の続き。
rbtestの件は後回し(ちと手がかり不足なので)
ヘルプのあるxmpfilterから。
そのヘルプの内容はと・・・
Usage: C:/wxruby/ruby/bin/xmpfilter [options] [inputfile] [-- cmdline args] Modes: -a, --annotations Annotate code (default) -u, --unittest Complete Test::Unit assertions. -s, --spec Complete RSpec expectations. --expectations Complete expectations expectations. -m, --markers Add # => markers. Interpreter options: -S, --interpreter FILE Use interpreter FILE. -I PATH Add PATH to $LOAD_PATH --dev Add this project's bin/ and lib/ to $LOAD_PATH. A directory with a Rakefile is considered a project base directory. -r LIB Require LIB before execution. -e, --eval, --stub=EXPR Evaluate EXPR after execution. --fork Use rct-fork-client if rct-fork is running. --rbtest Use rbtest. --detect-rbtest Use rbtest if '=begin test_*' blocks exist. Specific options: -l, --min-line-length N Align markers to N spaces. --rails Setting appropriate for Rails. (no warnings, find working directory, Test::Unit assertions) --[no-]poetry Whether to use extra parentheses. (default: use them) --[no-]warnings Whether to add warnings (# !>). (default: enabled) -q, --quiet Supress standard output. Misc options: --cd DIR Change working directory to DIR. --debug Write transformed source code to xmp-tmp.PID.rb. --tmpfile, --tempfile Use tmpfile instead of open3. (non-windows) -w, --width N Set width of multi-line annotation. (xmpfilter only) -h, --help Show this message -v, --version Show version information
やっぱりreadme読みます(^_^;)
C:\wxruby\ruby\lib\ruby\gems\1.9.1\gems\rcodetools-0.8.5.0
ココ(ウチの環境)にあるREADME.xmpfilter読むと、
- アノテーション
- 各テスティングフレームワーク利用支援
ができるっぽい。
早速、README.xmpfilterに書かれているサンプルを実行してみる。
1. ソースファイル作成
適当なフォルダにサンプルを貼り付けたファイルを作成します。
ex01_xmpfilter.rb
a, b = "foo", "baz" a + b # => a.size # =>
2. 実行
・コマンドプロンプトを開く
(1)[Windowsキー+Rキー]でファイル名を指定して実行ダイアログを開く
(2)名前コンボボックスに[cmd]と入力して、OKボタンを押下
・ソースファイルのあるフォルダにカレントディレクトリを移動する
(1)ソースファイルのあるドライブを入力
ex.Eドライブにソースファイルがある場合
>E:
(2)ソースファイルのあるフォルダのフルパスを入力
ex.E:¥191¥rcodetoolsにソースファイルがある場合
>cd \191\rcodetools
(3)ソースファイルが存在することを確認
以下のコマンドを入力して、ソースファイル名が表示されればOK
>dir /b
(4)実行
では、実行してみましょう。
>xmpfilter ex01_xmpfilter.rb
実行すると、以下のようにコマンドプロンプトに表示されます。
a, b = "foo", "baz" a + b # => "foobaz" a.size # => 3
すげぇ〜〜
あっ!rubyでは「#」以降から行末まではコメントとして扱われます。
コメントに式の値が表示されるなんてCoooooool!
これがアノテーションですね。
3. -m 実行
ヘルプに戻ってアノテーション絡みのオプションを探すと「-m」がありました。
どうやらアノテーション記号「# =>」をソースに追加してくれるっぽい。
早速使って見ましょう。
ex02_xmpfilter.rb
a, b = 1, 2 a + b a.size
>xmpfilter -m ex02_xmpfilter.rb
a, b = 1, 2 # => a + b # => a.size # =>
おぉ、注釈記号が追加されてコマンドプロンプトに表示された。
素晴らしいのだけど気になる点が・・・
というのは、実行するとコマンドプロンプトに素晴らしいコードが表示されるだけでソースファイルはそのまま。
当然といえば当然なんだけども、ヘルプを見た(英語なので読めているわけではない)感じだとemacsとかvimはソースに反映できるっぽいんだよね。
一応、無駄なあがきもしてみました(笑わないでw)
>xmpfilter -m ex02_xmpfilter.rb > ex02_xmpfilter.rb
下記エラーと共に、ソースが消えました(^_^;)
C:/wxruby/ruby/lib/ruby/1.9.1/optparse.rb:1262: warning: regexp match /.../n against to Windows-31J string C:/wxruby/ruby/lib/ruby/1.9.1/optparse.rb:1278: warning: regexp match /.../n against to Windows-31J string C:/wxruby/ruby/lib/ruby/gems/1.9.1/gems/rcodetools-0.8.5.0/bin/xmpfilter:76:in `read': No such file or directory - ex02_ xmpfilter.rb (Errno::ENOENT) from C:/wxruby/ruby/lib/ruby/gems/1.9.1/gems/rcodetools-0.8.5.0/bin/xmpfilter:76:in `<top (required)>' from C:/wxruby/ruby/bin/xmpfilter:19:in `load' from C:/wxruby/ruby/bin/xmpfilter:19:in `<main>'
がっくし。
しか〜し、このあと奇跡が起きます!