Module: Pleiades::Command::Routing::EventProccessor

Extended by:
ActiveSupport::Concern
Includes:
EventJudgeMethods
Included in:
Pleiades::Command::Router
Defined in:
lib/pleiades/core/command/routing/event_proccessor.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object (private)



61
62
63
64
65
# 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

Instance Method Details

#event(**keywords) ⇒ Object

イベントクラス名をリフレクションして、イベントメソッドを実行する。

EXAMPLE ## 使用しないtext pattern: ‘Hello’

## 使用するp event_name # => “text” event pattern: ‘Hello’



55
56
57
# File 'lib/pleiades/core/command/routing/event_proccessor.rb', line 55

def event(**keywords)
  __send__ __event_name__.to_sym, keywords
end

#match(**args) ⇒ Object

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

)



37
38
39
40
41
42
43
# 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