Created
November 22, 2013 16:44
-
-
Save jerryclinesmith/7602977 to your computer and use it in GitHub Desktop.
Chain a set of commands
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
module Chainer | |
STATUSES = [ STATUS_SUCCESS = :success, STATUS_FAIL = :fail ] | |
def self.execute(context, *steps) | |
steps.each do |step| | |
step.execute context | |
break if context.fail? | |
end | |
context | |
end | |
module Context | |
extend ActiveSupport::Concern | |
def status | |
@status || Chainer::STATUS_SUCCESS | |
end | |
def message | |
@message | |
end | |
def set_fail!(message) | |
self.message = message | |
self.status = Chainer::STATUS_FAIL | |
end | |
def success? | |
self.status == Chainer::STATUS_SUCCESS | |
end | |
def fail? | |
not success? | |
end | |
private | |
def status=(value) | |
@status = value | |
end | |
def message=(value) | |
@message = value | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment