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
10
11
# File 'lib/pub_sub/domain.rb', line 3

def method_missing(event_or_method_name, *event_data)
  if handler_name(event_or_method_name)
    event_payload = event_data.extract_options!
    EventTrace.load_from(event_payload.delete(:event_uid))
    const_get(handler_name(event_or_method_name)).new(event_payload).call!
  else
    super
  end
end

Instance Method Details

#handler_name(event_name) ⇒ Object



13
14
15
16
# File 'lib/pub_sub/domain.rb', line 13

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)


18
19
20
21
22
23
# File 'lib/pub_sub/domain.rb', line 18

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