Module: Messaging::Handle
- Included in:
- Controls::Handler::Anomaly::NoHandle::Example, Controls::Handler::BlockAndHandleMethod::Example, Controls::Handler::Example, Controls::Handler::HandleMethod::Example, Controls::Handler::UnregisteredMessage::Example
- Defined in:
- lib/messaging/handle.rb,
lib/messaging/handle/defaults.rb
Defined Under Namespace
Modules: Build, Call, Defaults, HandleMacro, Info, MessageRegistry Classes: Error
Class Method Summary collapse
Instance Method Summary collapse
- #call(message_or_message_data, strict: nil) ⇒ Object
- #handle_message(message, strict: nil) ⇒ Object
- #handle_message_data(message_data, strict: nil) ⇒ Object
-
#strict ⇒ Object
(also: #strict?)
Can’t null-coalesce here.
Class Method Details
.included(cls) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/messaging/handle.rb', line 5 def self.included(cls) cls.class_exec do include Dependency include TemplateMethod def handler_logger @handler_logger ||= Log.get(self) end attr_writer :handler_logger extend Build extend Call extend Info extend HandleMacro extend MessageRegistry template_method :configure attr_writer :strict end end |
Instance Method Details
#call(message_or_message_data, strict: nil) ⇒ Object
168 169 170 171 172 173 174 |
# File 'lib/messaging/handle.rb', line 168 def call(, strict: nil) if .is_a? Message (, strict: strict) else (, strict: strict) end end |
#handle_message(message, strict: nil) ⇒ Object
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/messaging/handle.rb', line 176 def (, strict: nil) strict ||= self.strict? handler_logger.trace(tags: [:dispatch, :message]) { "Dispatching message (Message class: #{.class.name})" } handler_logger.trace(tags: [:data, :message]) { .pretty_inspect } handler = self.class.handler() unless handler.nil? = . handler_logger.trace(tag: [:handle, :message]) { "Handling Message (Type: #{}, Method: #{handler})" } public_send(handler, ) handler_logger.info(tags: [:handle, :message]) { "Handled message (Message class: #{.class.name})" } handler_logger.info(tags: [:data, :message]) { .pretty_inspect } else if strict error_msg = "#{self.class.name} does not implement a handler for #{.}. Cannot handle the message." handler_logger.error(tag: :handle) { error_msg } raise Error, error_msg end end end |
#handle_message_data(message_data, strict: nil) ⇒ Object
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/messaging/handle.rb', line 204 def (, strict: nil) strict ||= self.strict? handler_logger.trace(tags: [:dispatch, :message_data]) { "Dispatching message data (Type: #{.type})" } handler_logger.trace(tags: [:data, :message_data]) { .pretty_inspect } = nil handler = self.class.handler() unless handler.nil? = .type = Messaging::Message::Info.canonize_name() = self.class..get() if == nil error_msg = "No message class is registered (Message Type: #{}, Handler: #{self.class.name})" handler_logger.error(tag: :handle) { error_msg } raise Error, error_msg end = Message::Import.(, ) = . handler_logger.trace(tag: [:handle, :message_data]) { "Handling Message Data (Type: #{}, Method: #{handler})" } public_send(handler, ) handler_logger.info(tags: [:handle, :message_data]) { "Handled message data (Type: #{.type})" } handler_logger.info(tags: [:data, :message_data]) { .pretty_inspect } else if respond_to?(:handle) = .type handler_logger.trace(tag: [:handle, :message_data]) { "Handling Message Data (Type: #{}, Method: handle" } handle() handler_logger.info(tags: [:handle, :message_data]) { "Handled message data (Type: #{.type})" } handler_logger.info(tags: [:data, :message_data]) { .pretty_inspect } = else if strict error_msg = "#{self.class.name} does not implement `handle'. Cannot handle message data." handler_logger.error(tag: :handle) { error_msg } raise Error, error_msg end end end end |