Skip to content

Commit 494305b

Browse files
committed
simplify class handlers
1 parent db58b4b commit 494305b

File tree

4 files changed

+6
-11
lines changed

4 files changed

+6
-11
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
venv
22
.pytest_cache
3-
.idea
3+
.idea
4+
__pycache__

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def handle_user_login(message):
1010
User.updateLastLoginTime()
1111

1212
# Class handlers
13-
@app.handler_class('user_logged_in')
13+
@app.handler('user_logged_in')
1414
class UserLoginHandler:
1515
def handle(self, message):
1616
User.updateLastLoginTime()

eggplant/core.py

+2-8
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,9 @@ def __init__(self, broker):
66
self._broker = broker
77
self._handlers = {}
88

9-
def handler(self, message_name):
9+
def handler(self, topic):
1010
def decorator_handler(func):
11-
self._handlers.update({message_name: func})
12-
13-
return decorator_handler
14-
15-
def handler_class(self, topic):
16-
def decorator_handler(clazz):
17-
self._handlers.update({topic: clazz})
11+
self._handlers.update({topic: func})
1812

1913
return decorator_handler
2014

tests/test_core.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def test_consume_with_class_handler():
66
app = Eggplant(broker)
77
received_messages = []
88

9-
@app.handler_class('password_expired')
9+
@app.handler('password_expired')
1010
class StubHandler:
1111
def handle(self, message):
1212
received_messages.append(message)

0 commit comments

Comments
 (0)