Class: EventHub::Handler

Inherits:
Object
  • Object
show all
Includes:
ActiveSupport::Callbacks
Defined in:
lib/event_hub/handler.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message) ⇒ Handler

Returns a new instance of Handler.



23
24
25
# File 'lib/event_hub/handler.rb', line 23

def initialize(message)
  @message = message
end

Instance Attribute Details

#messageObject (readonly)

Returns the value of attribute message.



8
9
10
# File 'lib/event_hub/handler.rb', line 8

def message
  @message
end

Class Method Details

.version(version = nil) ⇒ Object



18
19
20
21
# File 'lib/event_hub/handler.rb', line 18

def self.version(version = nil)
  @version = version if version
  @version
end

Instance Method Details

#handleObject



10
11
12
13
14
15
16
# File 'lib/event_hub/handler.rb', line 10

def handle
  run_callbacks :handle do
    validate!
    call
    @message.ack
  end
end

#on_incorrect_versionObject

Raises:



27
28
29
# File 'lib/event_hub/handler.rb', line 27

def on_incorrect_version
  raise IncorrectVersion
end

#validate!Object



31
32
33
# File 'lib/event_hub/handler.rb', line 31

def validate!
  on_incorrect_version if @message.version != self.class.version
end