Module: Messaging::Handle::HandleMacro

Defined in:
lib/messaging/handle.rb

Defined Under Namespace

Classes: Error

Instance Method Summary collapse

Instance Method Details

#define_handler_method(message_class, &blk) ⇒ Object



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/messaging/handle.rb', line 133

def define_handler_method(message_class, &blk)
  handler_method_name = handler_method_name(message_class)

  if blk.nil?
    error_msg = "Handler for #{message_class.name} is not correctly defined. It must have a block."
    handler_logger.error(tag: :handle) { error_msg }
    raise Error, error_msg
  end

  send(:define_method, handler_method_name, &blk)

  handler_method = instance_method(handler_method_name)

  unless handler_method.arity == 1
    error_msg = "Handler for #{message_class.name} is not correctly defined. It can only have a single parameter."
    handler_logger.error(tag: :handle) { error_msg }
    raise Error, error_msg
  end

  handler_method_name
end

#handle_macro(message_class, &blk) ⇒ Object Also known as: handle



124
125
126
127
128
129
130
# File 'lib/messaging/handle.rb', line 124

def handle_macro(message_class, &blk)
  handler_method_name = define_handler_method(message_class, &blk)

  message_registry.register(message_class)

  handler_method_name
end

#handler_loggerObject



120
121
122
# File 'lib/messaging/handle.rb', line 120

def handler_logger
  @handler_logger ||= Log.get(self)
end