Skip to content

Commit

Permalink
Small improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
pabloh committed Nov 7, 2017
1 parent 290798a commit c600433
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions lib/pathway.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,15 @@ def inherited(subclass)
module InstanceMethods
extend Forwardable

def result_key
self.class.result_key
end
delegate :result_key => 'self.class'
delegate %i[result success failure] => Result

alias :wrap :result

def call(*)
fail "must implement at subclass"
end

delegate %i[result success failure] => Result

alias :wrap :result

def error(type, message: nil, details: nil)
failure Error.new(type: type, message: message, details: details)
end
Expand Down Expand Up @@ -155,18 +152,18 @@ def map(callable)
@result = @result.then(bl)
end

def sequence(with_seq, &bl)
def sequence(steps_wrapper, &steps)
@result.then do |state|
seq = -> { @result = dup.run(&bl) }
_callable(with_seq).call(seq, state)
seq = -> { @result = dup.run(&steps) }
_callable(steps_wrapper).call(seq, state)
end
end

def guard(cond, &bl)
def guard(cond, &steps)
cond = _callable(cond)
sequence(-> seq, state {
seq.call if cond.call(state)
}, &bl)
}, &steps)
end

private
Expand Down

0 comments on commit c600433

Please sign in to comment.