Created
October 10, 2016 09:17
-
-
Save volodymyr-nt/aa241534f9a1c25ef4fa0a01882fc4e4 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
| # base implementation of service object pattern | |
| class Service | |
| def self.call(*params) | |
| new(*params).call | |
| end | |
| class ServiceResponse | |
| def error? | |
| !success? | |
| end | |
| end | |
| class SuccessResponse < ServiceResponse | |
| attr_reader :data | |
| def initialize(data) | |
| @data = data | |
| end | |
| def success? | |
| true | |
| end | |
| end | |
| class ErrorResponse < ServiceResponse | |
| attr_reader :errors | |
| def initialize(errors = []) | |
| @errors = error_messages | |
| end | |
| def push(error) | |
| @errors.push(error) | |
| end | |
| def success? | |
| false | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment