module Pleiades::Command::Routing::EventProccessor
Public Instance Methods
event(**keywords)
click to toggle source
イベントクラス名をリフレクションして、イベントメソッドを実行する。
EXAMPLE ## 使用しない text pattern: 'Hello'
## 使用する p event_name # => “text” event pattern: 'Hello'
# File lib/pleiades/core/command/routing/event_proccessor.rb, line 55 def event(**keywords) __send__ __event_name__.to_sym, keywords end
match(**args)
click to toggle source
match 複数のイベントメソッドを実行する。
EXAMPLE(以下のmatchなし、matchありは同義)
## matchなし scope 'line' do
action :greet do text pattern: 'Hello, world' sticker package_id: '1', sticker_id: '1' end
end
## matchあり match(
via: { text: { pattern: 'Hello, world' }, sticker: { package_id: '1', sticker_id: '1' } }, scope: 'line', action: :greet
)
# File lib/pleiades/core/command/routing/event_proccessor.rb, line 37 def match(**args) validate_match_keywords(args) args.delete(:via).each_pair do |event, val| __send__ event, merge_from_match(val, args) end end
Private Instance Methods
event_executable?(args)
click to toggle source
# File lib/pleiades/core/command/routing/event_proccessor.rb, line 84 def event_executable?(args) exe_conditions = [route_unfixid?, matching_events?(args[:type])] exe_conditions << callable_talk_type?([args[:talk_type]]) if args.key?(:talk_type) exe_conditions.all? end
event_types()
click to toggle source
# File lib/pleiades/core/command/routing/event_proccessor.rb, line 103 def event_types Pleiades::Constants::Events::TYPES end
exe_event_method(args)
click to toggle source
# File lib/pleiades/core/command/routing/event_proccessor.rb, line 71 def exe_event_method(args) on_execute = validate_event_keywords(args) && event_executable?(args) return unless on_execute method_name = args[:type] if judge_method_defined?(method_name) return unless method(judge_method(method_name)).call(args) end route_fix!(args) end
matching_events?(method_name)
click to toggle source
# File lib/pleiades/core/command/routing/event_proccessor.rb, line 111 def matching_events?(method_name) __event_name__ == method_name.to_s end
merge_from_match(via, arg)
click to toggle source
# File lib/pleiades/core/command/routing/event_proccessor.rb, line 92 def merge_from_match(via, arg) arg.merge(via) do |key, a_val, v_val| case key when :scope, :concern [a_val, v_val].flatten else v_val end end end
method_missing(method, *args, &block)
click to toggle source
Calls superclass method
# File lib/pleiades/core/command/routing/event_proccessor.rb, line 61 def method_missing(method, *args, &block) return super unless event_types.include?(method.to_s) exe_event_method((args.inject(&:merge) || {}).merge(type: method)) end
respond_to_missing?(method, *args, &block)
click to toggle source
Calls superclass method
# File lib/pleiades/core/command/routing/event_proccessor.rb, line 67 def respond_to_missing?(method, *args, &block) event_types.include?(method.to_s) || super end
route_fix!(args)
click to toggle source
# File lib/pleiades/core/command/routing/event_proccessor.rb, line 115 def route_fix!(args) Pleiades::Command::Router.path_info = Pleiades::Command::Routing::Result.create(@options, args) end
route_unfixid?()
click to toggle source
# File lib/pleiades/core/command/routing/event_proccessor.rb, line 107 def route_unfixid? !Router.path_found? end