-
Notifications
You must be signed in to change notification settings - Fork 912
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
msggen: introduce chain of responsibility pattern to make msggen exte…
…nsible Changelog-Added: msggen: introduce chain of responsibility pattern to make msggen extensible Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
- Loading branch information
1 parent
80db867
commit 4e902fb
Showing
7 changed files
with
195 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .generator import IGenerator, GeneratorChain # noqa | ||
from .grpc import GrpcGenerator, GrpcConverterGenerator, GrpcUnconverterGenerator, GrpcServerGenerator # noqa | ||
from .rust import RustGenerator # noqa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
""" | ||
Generator interface! | ||
author: https://github.com/vincenzopalazzo | ||
""" | ||
from abc import ABC, abstractmethod | ||
|
||
from msggen.model import Service | ||
|
||
|
||
class IGenerator(ABC): | ||
""" | ||
Change of responsibility handler that need to be | ||
implemented by all the generators. | ||
""" | ||
|
||
@abstractmethod | ||
def generate(self, service: Service): | ||
pass | ||
|
||
|
||
class GeneratorChain: | ||
""" | ||
Chain responsibility patter implementation to generalize | ||
the generation method. | ||
""" | ||
|
||
def __init__(self): | ||
self.generators = [] | ||
|
||
def add_generator(self, generator: IGenerator) -> None: | ||
self.generators.append(generator) | ||
|
||
def generate(self, service: Service) -> None: | ||
for _, generator in enumerate(self.generators): | ||
generator.generate(service) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .utils import load_jsonrpc_method, load_jsonrpc_service, repo_root # noqa |
Oops, something went wrong.