Last active
August 29, 2015 14:12
-
-
Save mrkplt/35d6d1df5b0105fdd577 to your computer and use it in GitHub Desktop.
A sort of fast mock up of how I think you could implement business logic that would be separated from data layer and controller.
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
| class BusinessObject | |
| class LambdaError < StandardError; end; | |
| def initialize(*args) | |
| post_init(args) | |
| end | |
| private | |
| attr_reader :success_lambda, :failure_lambda | |
| def post_init(args) | |
| @success_lambda = args[:success] | |
| @failure_lambda = args[:failure] | |
| end | |
| def success | |
| begin | |
| success_lambda.call | |
| rescue NoMethodError | |
| raise LambdaError, 'A lambda for success must be provided' | |
| end | |
| end | |
| def failure | |
| begin | |
| failure_lambda.call | |
| rescue NoMethodError | |
| raise LambdaError, 'A lambda for failure must be provided' | |
| end | |
| 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
| def SaveObjekt < BusinessObject | |
| def intialize(some_objekt, *args) | |
| @objekt = some_objekt | |
| super(*args) | |
| end | |
| def perform | |
| @objekt.action ? success : failure | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment