Created
October 25, 2016 13:39
-
-
Save oinak/d77205b17857862f3e309e2e5be21dd0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| # to be called: | |
| # ExampleService[1, {some: 'opt'}] | |
| class ExampleService < Services::Base | |
| # customize your setup | |
| def initialize(concrete, arguments = {}) | |
| @concrete = concrete | |
| @arguments = arguments | |
| end | |
| # customize your processing | |
| def call | |
| end | |
| end |
This file contains hidden or 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
| module Services | |
| class Base | |
| class << self | |
| def call | |
| new(*args).call | |
| end | |
| alias_method :[], :call | |
| end | |
| private_class_method :new | |
| # to be customized on subclases | |
| def call | |
| raise NotImplementedError | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment