pluggaloid gemをmrubyにポーティングしたものです。
mikutterのプラグイン機構です。 登録したプラグイン同士がイベントを使って通信できるようになります。
Add conf.gem line to your build_config.rb
:
MRuby::Build.new do |conf|
# ... (snip) ...
conf.gem :github => 'shibafu528/mruby-pluggaloid'
end
main = Pluggaloid.new(Delayer.generate_class(priority: %i<high normal low>, default: :normal))
main.Plugin.create(:write_to_stdout) do
on_logging do |message|
puts "logging: #{message}"
end
end
main.Plugin.call(:logging, "boot.")
main.Plugin.call(:logging, "event test.")
main.Plugin.call(:logging, "exit.")
main.Delayer.run while not main.Delayer.empty?
Pluggaloid::newは、プラグイン機構を制御するためのDelayer, Plugin, Event, Listener, Filterのサブクラスを新しく作って返すメソッドです。 戻り値はStructで、それぞれのクラス名がメンバの名前になっています。
Member | Description |
---|---|
Delayer | Pluggaloid::new に渡したDelayer |
Plugin | Pluggaloid::Plugin のサブクラス |
Event | Pluggaloid::Event のサブクラス |
Listener | Pluggaloid::Listener のサブクラス |
Filter | Pluggaloid::Filter のサブクラス |
コンストラクタの唯一の引数には Delayer.generate_class(priority: %i<high normal low>, default: :normal)
のように、優先順位付きでデフォルト優先度が設定されたDelayerを渡します。
- Fork it ( https://github.com/shibafu528/mruby-pluggaloid/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request