Module: PubSub::Domain

Defined in:
lib/pub_sub/domain.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(event_or_method_name, *event_data) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/pub_sub/domain.rb', line 3

def method_missing(event_or_method_name, *event_data)
  if handler_name(event_or_method_name)
    const_get(handler_name(event_or_method_name)).new(*event_data).call!
  else
    super
  end
end

Instance Method Details

#handler_name(event_name) ⇒ Object



11
12
13
14
# File 'lib/pub_sub/domain.rb', line 11

def handler_name(event_name)
  return nil unless event_name.to_s.start_with?(/[a-z_]+__/)
  "#{event_name.to_s.camelize}Handler"
end

#respond_to_missing?(event_or_method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
19
20
21
# File 'lib/pub_sub/domain.rb', line 16

def respond_to_missing?(event_or_method_name, include_private = false)
  return super unless handler_name(event_or_method_name)
  const_get(handler_name(event_or_method_name))
rescue NameError
  super
end