-
Notifications
You must be signed in to change notification settings - Fork 0
プラグインの命名規則
ocha edited this page Feb 15, 2015
·
2 revisions
プラグインのモジュール名、ファイル名についての規則です。
Active Support の String#camelize
や String#underscore
で相互変換を行っているため、適合していないと動作しません。
まずモジュール名とファイル名の例を示します。
# /lib/rgrb/plugin/some_plugin/generator.rb
module RGRB
module Plugin
module SomePlugin
class Generator
# ジェネレータの内容
end
end
end
end
# /spec/rgrb/plugin/some_plugin/generator_spec.rb
require_relative '../../../spec_helper'
require 'rgrb/plugin/some_plugin/generator'
describe RGRB::Plugin::SomePlugin::Generator
let(:generator) { described_class.new }
# テストケースを書く
end
「SomePlugin」のようなアッパーキャメルケースの名前のモジュールとします。これを RGRB::Plugin
モジュール内に作ります。このモジュールの中にプラグインの構成部分を作っていきます。
「some_plugin」のようなスネークケースとします。
まずディレクトリ /lib/rgrb/plugin/some_plugin/ を作ります。この中にプラグインの構成部分のファイルを入れていきます。例えば、上述のジェネレータのファイルのパスは /lib/rgrb/plugin/some_plugin/generator.rb とします。
テストケースを作る場合、まずディレクトリ /spec/rgrb/plugin/some_plugin/ を作ります。ここに RSpec 用のファイルを入れていきます。RSpec 用のファイルの名前は some_class_spec.rb とします。例えば、上述のジェネレータのテストケースのファイルのパスは /spec/rgrb/plugin/some_plugin/generator_spec.rb とします。