Module: Rlyeh::Dispatcher::ClassMethods
- Defined in:
- lib/rlyeh/dispatcher.rb
Instance Method Summary collapse
Instance Method Details
#callbacks(target) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/rlyeh/dispatcher.rb', line 10 def callbacks(target) @dispatchers ||= [] callbacks = @dispatchers.select do |item| key = item[0] case key when Regexp then key =~ target else key == target end end.map { |item| item[1] }.flatten if superclass.respond_to?(:callbacks) superclass.callbacks(target) + callbacks else callbacks end end |
#on(*args, &block) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/rlyeh/dispatcher.rb', line 27 def on(*args, &block) = Rlyeh::Utils. args target = args.shift target = Array([:scope]) + Array(target) if [String, Symbol].any? { |type| target.is_a?(type) } target = target.join('.') if target.is_a?(Array) @dispatchers ||= [] @dispatchers << [target, Rlyeh::Utils.generate_method(self, "__on_#{target}", block)] end |