Skip to content

Commit

Permalink
Merge pull request #4 from codequest-eu/feature/soft-failure
Browse files Browse the repository at this point in the history
Add an option to softly fail a pipe
  • Loading branch information
marcinwyszynski committed Feb 24, 2016
2 parents 66349ba + 2507ccc commit 3367601
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion codequest_pipes.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Gem::Specification.new do |spec|
spec.name = 'codequest_pipes'
spec.version = '0.2.0'
spec.version = '0.2.1'

spec.author = 'codequest'
spec.email = '[email protected]'
Expand Down
10 changes: 9 additions & 1 deletion lib/codequest_pipes/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,22 @@ def add(values)
end
end

# Quietly fail the pipe, allowing the error to be saved and accessed from
# the Context.
#
# @param error [Any] Error to be set.
def halt(error = 'Execution stopped')
@error = error
end

# Explicitly fail the pipe, allowing the error to be saved and accessed from
# the Context.
#
# @param error [Any] Error to be set.
#
# @raise [ExecutionTerminated]
def terminate(error)
@error = error
halt(error)
fail ExecutionTerminated, error
end

Expand Down
2 changes: 1 addition & 1 deletion lib/codequest_pipes/pipe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ def self.|(other)
end

def self.call(ctx)
return ctx if ctx.error
_validate_ctx(_required_context_elements, ctx)
new(ctx).call
_validate_ctx(_provided_context_elements, ctx)
ctx
end

def self.require_context(*args)
Expand Down

0 comments on commit 3367601

Please sign in to comment.