Module: ProconBypassMan::Callbacks::ClassMethods

Defined in:
lib/procon_bypass_man/support/callbacks.rb

Instance Method Summary collapse

Instance Method Details

#define_callbacks(name) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/procon_bypass_man/support/callbacks.rb', line 16

def define_callbacks(name)
  self.singleton_class.attr_accessor "_#{name}_callbacks"
  send "_#{name}_callbacks=", [name] # CallbacksChain

  module_eval <<-RUBY, __FILE__, __LINE__ + 1
    def _run_#{name}_callbacks(&block)
      __run_callbacks__(_#{name}_callbacks, &block)
    end
  RUBY
end

#set_callback(kind, filter, chain_method, &block) ⇒ Object

TODO: 存在しないメソッドへのcallbackを登録したらエラーにする



28
29
30
31
32
33
34
35
36
# File 'lib/procon_bypass_man/support/callbacks.rb', line 28

def set_callback(kind, filter, chain_method, &block)
  self.__callbacks ||= {}
  self.__callbacks[kind] ||= CallbackChain.new
  self.__callbacks[kind].append Callback.new(
    filter: filter,
    chain_method: chain_method,
    block: block,
  )
end