Class: RailwayIpc::Handler

Inherits:
Object
  • Object
show all
Defined in:
lib/railway_ipc/handler.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.blockObject (readonly)

Returns the value of attribute block.



6
7
8
# File 'lib/railway_ipc/handler.rb', line 6

def block
  @block
end

Class Method Details

.handle(&block) ⇒ Object



9
10
11
# File 'lib/railway_ipc/handler.rb', line 9

def self.handle(&block)
  @block = block
end

Instance Method Details

#handle(message) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/railway_ipc/handler.rb', line 13

def handle(message)
  RailwayIpc.logger.info('Handling message', log_message_options(message))
  response = self.class.block.call(message)
  if response.success?
    RailwayIpc.logger.info('Successfully handled message', log_message_options(message))
  else
    RailwayIpc.logger.error('Failed to handle message', log_message_options(message))
  end

  response
end